@Test public void testVerifyMojo() throws Exception { TestResourcesEx testResourcesEx = new TestResourcesEx(resources); String testDirWithContract = testResourcesEx.getBasedirWithContract(); testResourcesEx.createMojo(rule, "verify"); MavenProject project = mock(MavenProject.class); testResourcesEx.setVariableValueToObject("project", project); try { given(project.getRuntimeClasspathElements()).willReturn(testResourcesEx.getRuntimeUrlPath(testDirWithContract)); testResourcesEx.setVariableValueToObject("sourceType", "code"); testResourcesEx.setVariableValueToObject("destinationContractPath", testResourcesEx.getContractDestination()); testResourcesEx.execute(); } catch (RuntimeException e) { fail("Run 'testVerifyMojo' failed, unexpected to catch RuntimeException: " + e.getMessage()); } try { testResourcesEx.setVariableValueToObject("sourceType", "contract"); testResourcesEx.setVariableValueToObject("sourceContractPath", null); testResourcesEx.execute(); fail("Run 'testVerifyMojo' failed, expected to occur RuntimeException but not"); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("Failed to verify contract")); } try { testResourcesEx.setVariableValueToObject("sourceType", "contract"); testResourcesEx.setVariableValueToObject("sourceContractPath", testResourcesEx.getContractLocation()); testResourcesEx.setVariableValueToObject("destinationContractPath", null); testResourcesEx.execute(); fail("Run 'testVerifyMojo' failed, expected to occur RuntimeException but not"); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("Failed to verify contract")); } try { testResourcesEx.setVariableValueToObject("sourceType", "contract"); testResourcesEx.setVariableValueToObject("sourceContractPath", testResourcesEx.getContractLocation()); testResourcesEx.setVariableValueToObject("destinationContractPath", testResourcesEx.getContractDestination()); testResourcesEx.execute(); } catch (RuntimeException e) { fail("Run 'testVerifyMojo' failed, unexpected to catch RuntimeException: " + e.getMessage()); } }
@Override public void execute() { String contractFileType = "yaml"; switch (SourceType.valueOf(sourceType.toUpperCase())) { case CODE: try { sourceContractPath = FileUtils.createTempDirectory("target/tmp-contract").toFile().getCanonicalPath(); GenerateUtil.generateContract(project, sourceContractPath, contractFileType, "default"); } catch (RuntimeException | IOException e) { throw new RuntimeException("Failed to generate contract from code", e); } break; case CONTRACT: break; default: throw new RuntimeException("Not support source type " + sourceType); } try { Map<String, byte[]> sourceContractGroup = FileUtils.getFilesGroupByFilename(sourceContractPath); Map<String, byte[]> destinationContractGroup = FileUtils.getFilesGroupByFilename(destinationContractPath); sourceContractGroup.forEach((contractName, swagger) -> { byte[] sourceSwagger = destinationContractGroup.get(contractName); ContractComparator contractComparator = new ContractComparator(new String(sourceSwagger), new String(swagger)); if (!contractComparator.equals()) { LOGGER.info("Contract is not matched, difference is as follows"); LOGGER.info(destinationContractPath + "/" + contractName + " vs " + sourceContractPath + "/" + contractName); contractComparator.splitPrintToScreen(); } else { LOGGER.info("Succee, contract verification passed"); } }); } catch (IOException e) { throw new RuntimeException("Failed to verify contract ", e); } }
VerifyMojo extends AbstractMojo { @Override public void execute() { String contractFileType = "yaml"; switch (SourceType.valueOf(sourceType.toUpperCase())) { case CODE: try { sourceContractPath = FileUtils.createTempDirectory("target/tmp-contract").toFile().getCanonicalPath(); GenerateUtil.generateContract(project, sourceContractPath, contractFileType, "default"); } catch (RuntimeException | IOException e) { throw new RuntimeException("Failed to generate contract from code", e); } break; case CONTRACT: break; default: throw new RuntimeException("Not support source type " + sourceType); } try { Map<String, byte[]> sourceContractGroup = FileUtils.getFilesGroupByFilename(sourceContractPath); Map<String, byte[]> destinationContractGroup = FileUtils.getFilesGroupByFilename(destinationContractPath); sourceContractGroup.forEach((contractName, swagger) -> { byte[] sourceSwagger = destinationContractGroup.get(contractName); ContractComparator contractComparator = new ContractComparator(new String(sourceSwagger), new String(swagger)); if (!contractComparator.equals()) { LOGGER.info("Contract is not matched, difference is as follows"); LOGGER.info(destinationContractPath + "/" + contractName + " vs " + sourceContractPath + "/" + contractName); contractComparator.splitPrintToScreen(); } else { LOGGER.info("Succee, contract verification passed"); } }); } catch (IOException e) { throw new RuntimeException("Failed to verify contract ", e); } } }
VerifyMojo extends AbstractMojo { @Override public void execute() { String contractFileType = "yaml"; switch (SourceType.valueOf(sourceType.toUpperCase())) { case CODE: try { sourceContractPath = FileUtils.createTempDirectory("target/tmp-contract").toFile().getCanonicalPath(); GenerateUtil.generateContract(project, sourceContractPath, contractFileType, "default"); } catch (RuntimeException | IOException e) { throw new RuntimeException("Failed to generate contract from code", e); } break; case CONTRACT: break; default: throw new RuntimeException("Not support source type " + sourceType); } try { Map<String, byte[]> sourceContractGroup = FileUtils.getFilesGroupByFilename(sourceContractPath); Map<String, byte[]> destinationContractGroup = FileUtils.getFilesGroupByFilename(destinationContractPath); sourceContractGroup.forEach((contractName, swagger) -> { byte[] sourceSwagger = destinationContractGroup.get(contractName); ContractComparator contractComparator = new ContractComparator(new String(sourceSwagger), new String(swagger)); if (!contractComparator.equals()) { LOGGER.info("Contract is not matched, difference is as follows"); LOGGER.info(destinationContractPath + "/" + contractName + " vs " + sourceContractPath + "/" + contractName); contractComparator.splitPrintToScreen(); } else { LOGGER.info("Succee, contract verification passed"); } }); } catch (IOException e) { throw new RuntimeException("Failed to verify contract ", e); } }  }
VerifyMojo extends AbstractMojo { @Override public void execute() { String contractFileType = "yaml"; switch (SourceType.valueOf(sourceType.toUpperCase())) { case CODE: try { sourceContractPath = FileUtils.createTempDirectory("target/tmp-contract").toFile().getCanonicalPath(); GenerateUtil.generateContract(project, sourceContractPath, contractFileType, "default"); } catch (RuntimeException | IOException e) { throw new RuntimeException("Failed to generate contract from code", e); } break; case CONTRACT: break; default: throw new RuntimeException("Not support source type " + sourceType); } try { Map<String, byte[]> sourceContractGroup = FileUtils.getFilesGroupByFilename(sourceContractPath); Map<String, byte[]> destinationContractGroup = FileUtils.getFilesGroupByFilename(destinationContractPath); sourceContractGroup.forEach((contractName, swagger) -> { byte[] sourceSwagger = destinationContractGroup.get(contractName); ContractComparator contractComparator = new ContractComparator(new String(sourceSwagger), new String(swagger)); if (!contractComparator.equals()) { LOGGER.info("Contract is not matched, difference is as follows"); LOGGER.info(destinationContractPath + "/" + contractName + " vs " + sourceContractPath + "/" + contractName); contractComparator.splitPrintToScreen(); } else { LOGGER.info("Succee, contract verification passed"); } }); } catch (IOException e) { throw new RuntimeException("Failed to verify contract ", e); } }  @Override void execute(); }
VerifyMojo extends AbstractMojo { @Override public void execute() { String contractFileType = "yaml"; switch (SourceType.valueOf(sourceType.toUpperCase())) { case CODE: try { sourceContractPath = FileUtils.createTempDirectory("target/tmp-contract").toFile().getCanonicalPath(); GenerateUtil.generateContract(project, sourceContractPath, contractFileType, "default"); } catch (RuntimeException | IOException e) { throw new RuntimeException("Failed to generate contract from code", e); } break; case CONTRACT: break; default: throw new RuntimeException("Not support source type " + sourceType); } try { Map<String, byte[]> sourceContractGroup = FileUtils.getFilesGroupByFilename(sourceContractPath); Map<String, byte[]> destinationContractGroup = FileUtils.getFilesGroupByFilename(destinationContractPath); sourceContractGroup.forEach((contractName, swagger) -> { byte[] sourceSwagger = destinationContractGroup.get(contractName); ContractComparator contractComparator = new ContractComparator(new String(sourceSwagger), new String(swagger)); if (!contractComparator.equals()) { LOGGER.info("Contract is not matched, difference is as follows"); LOGGER.info(destinationContractPath + "/" + contractName + " vs " + sourceContractPath + "/" + contractName); contractComparator.splitPrintToScreen(); } else { LOGGER.info("Succee, contract verification passed"); } }); } catch (IOException e) { throw new RuntimeException("Failed to verify contract ", e); } }  @Override void execute();  }