You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2019/07/27 09:05:05 UTC
[servicecomb-toolkit] 02/04: SCB-1383 support toolkit maven plugin
commands that generating code
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git
commit f796a482f433fe2f4db5b1bf9df31306d7e7aa2f
Author: MabinGo <bi...@huawei.com>
AuthorDate: Fri Jul 26 15:26:47 2019 +0800
SCB-1383 support toolkit maven plugin commands that generating code
fix bug according code review
Signed-off-by: MabinGo <bi...@huawei.com>
---
.../servicecomb/toolkit/cli/DocGenerate.java | 16 +++---------
.../toolkit/codegen/DefaultCodeGenerator.java | 9 ++-----
.../servicecomb/toolkit/codegen/GeneratorTest.java | 16 ++++++++----
.../servicecomb/toolkit/common/FileUtils.java | 14 +++-------
.../servicecomb/toolkit/common/MyersAlgorithm.java | 4 +--
.../servicecomb/toolkit/common/FileUtilsTest.java | 4 +--
.../toolkit/common/TextCompareTest.java | 2 +-
.../contractgen/DefaultContractsGenerator.java | 9 +++----
.../contractgen/DefaultContractsGeneratorTest.java | 7 ++++-
.../org/apache/servicecomb/toolkit/Generator.java | 2 +-
.../docgen/ContractsSwaggerUIGenerator.java | 6 ++---
.../servicecomb/toolkit/plugin/GenerateMojo.java | 30 +++++++++++-----------
.../servicecomb/toolkit/plugin/GenerateUtil.java | 24 +++++++----------
.../servicecomb/toolkit/plugin/VerifyMojo.java | 10 ++++----
.../toolkit/plugin/GenerateMojoTest.java | 3 ++-
.../toolkit/plugin/GenerateUtilTest.java | 9 +++----
16 files changed, 72 insertions(+), 93 deletions(-)
diff --git a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java
index 3f880e6..7426846 100755
--- a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java
+++ b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java
@@ -62,7 +62,6 @@ public class DocGenerate implements Runnable {
try {
Path specPath = Paths.get(specFile);
- boolean[] retValues = new boolean[1];
String[] fileName = new String[1];
DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, format);
@@ -78,11 +77,7 @@ public class DocGenerate implements Runnable {
docGeneratorConfig.put("outputPath",
output + File.separator + file.toFile().getName().substring(0, file.toFile().getName().indexOf(".")));
docGenerator.configure(docGeneratorConfig);
- retValues[0] = docGenerator.generate();
- if (retValues[0]) {
- fileName[0] = file.toFile().getName();
- return FileVisitResult.TERMINATE;
- }
+ docGenerator.generate();
return super.visitFile(file, attrs);
}
@@ -94,7 +89,7 @@ public class DocGenerate implements Runnable {
docGeneratorConfig.put("outputPath", output + File.separator + new File(specFile).getName()
.substring(0, new File(specFile).getName().indexOf(".")));
docGenerator.configure(docGeneratorConfig);
- retValues[0] = docGenerator.generate();
+ docGenerator.generate();
} else {
fileName[0] = specFile;
@@ -102,12 +97,7 @@ public class DocGenerate implements Runnable {
docGeneratorConfig.put("outputPath", output + File.separator + new File(specFile).getName()
.substring(0, new File(specFile).getName().indexOf(".")));
docGenerator.configure(docGeneratorConfig);
- retValues[0] = docGenerator.generate();
- }
-
- if (!retValues[0]) {
- LOGGER.error("Failed to generate document base on file {}", fileName[0]);
- return;
+ docGenerator.generate();
}
LOGGER.info("Success to generate document, the directory is: {}", output);
diff --git a/codegen/src/main/java/org/apache/servicecomb/toolkit/codegen/DefaultCodeGenerator.java b/codegen/src/main/java/org/apache/servicecomb/toolkit/codegen/DefaultCodeGenerator.java
index 05760c5..201eb76 100755
--- a/codegen/src/main/java/org/apache/servicecomb/toolkit/codegen/DefaultCodeGenerator.java
+++ b/codegen/src/main/java/org/apache/servicecomb/toolkit/codegen/DefaultCodeGenerator.java
@@ -41,12 +41,7 @@ public class DefaultCodeGenerator implements CodeGenerator {
}
@Override
- public boolean generate() {
-
- if (generator.generate().size() > 0) {
- return true;
- }
-
- return false;
+ public void generate() {
+ generator.generate();
}
}
diff --git a/codegen/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java b/codegen/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java
index 2e4a7db..378554e 100755
--- a/codegen/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java
+++ b/codegen/src/test/java/org/apache/servicecomb/toolkit/codegen/GeneratorTest.java
@@ -17,6 +17,8 @@
package org.apache.servicecomb.toolkit.codegen;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
@@ -55,8 +57,13 @@ public class GeneratorTest {
configurator.setOutputDir(tempDir.toFile().getCanonicalPath() + "/ServiceComb");
configurator.setInputSpec(specFilePath.toFile().getCanonicalPath());
DefaultCodeGenerator codeGenerator = new DefaultCodeGenerator();
- codeGenerator.configure(Collections.singletonMap("configurator",configurator));
- boolean generateResult = codeGenerator.generate();
+ codeGenerator.configure(Collections.singletonMap("configurator", configurator));
+
+ try {
+ codeGenerator.generate();
+ } catch (RuntimeException e) {
+ fail();
+ }
Object internalGenerator = ReflectUtils.getProperty(codeGenerator, "generator");
Assert.assertEquals(DefaultGenerator.class, internalGenerator.getClass());
@@ -65,18 +72,17 @@ public class GeneratorTest {
Assert.assertEquals("ServiceComb", ((ServiceCombCodegen) swaggerCodegenConfig).getName());
Assert.assertEquals(CodegenType.SERVER, ((ServiceCombCodegen) swaggerCodegenConfig).getTag());
- Assert.assertTrue(generateResult);
tempDir.toFile().deleteOnExit();
}
@Test
public void getCodeGeneratorInstanse() {
- CodeGenerator defaultCodeGenerator = GeneratorFactory.getGenerator(CodeGenerator.class,"default");
+ CodeGenerator defaultCodeGenerator = GeneratorFactory.getGenerator(CodeGenerator.class, "default");
Assert.assertNotNull(defaultCodeGenerator);
Assert.assertTrue(defaultCodeGenerator.canProcess("default"));
- CodeGenerator unknownCodeGenerator = GeneratorFactory.getGenerator(CodeGenerator.class,"unknown");
+ CodeGenerator unknownCodeGenerator = GeneratorFactory.getGenerator(CodeGenerator.class, "unknown");
Assert.assertNull(unknownCodeGenerator);
}
}
diff --git a/common/src/main/java/org/apache/servicecomb/toolkit/common/FileUtils.java b/common/src/main/java/org/apache/servicecomb/toolkit/common/FileUtils.java
index d133034..7915216 100755
--- a/common/src/main/java/org/apache/servicecomb/toolkit/common/FileUtils.java
+++ b/common/src/main/java/org/apache/servicecomb/toolkit/common/FileUtils.java
@@ -34,7 +34,7 @@ public class FileUtils {
public static void createDirectory(String pathName) throws IOException {
if (pathName == null) {
- throw new IOException("path is null");
+ throw new IOException("Path is null");
}
File path = new File(pathName);
@@ -43,7 +43,7 @@ public class FileUtils {
}
if (!path.mkdirs()) {
- throw new IOException("failed to create directory");
+ throw new IOException("Failed to create directory");
}
}
@@ -57,11 +57,11 @@ public class FileUtils {
public static Map<String, byte[]> getFilesGroupByFilename(String pathName) throws IOException {
if (pathName == null) {
- throw new IOException("path is null");
+ throw new IOException("Path is null");
}
if (!new File(pathName).exists()) {
- throw new IOException("path " + pathName + " is not exists");
+ throw new IOException("Path " + pathName + " is not exists");
}
Map<String, byte[]> filesGroup = new HashMap<>();
@@ -82,12 +82,6 @@ public class FileUtils {
File path = new File(pathName);
-/*
- if (!path.exists()) {
- return;
- }
-*/
-
if (!path.isDirectory()) {
Files.delete(Paths.get(pathName));
return;
diff --git a/common/src/main/java/org/apache/servicecomb/toolkit/common/MyersAlgorithm.java b/common/src/main/java/org/apache/servicecomb/toolkit/common/MyersAlgorithm.java
index 17ff7d1..09e670f 100755
--- a/common/src/main/java/org/apache/servicecomb/toolkit/common/MyersAlgorithm.java
+++ b/common/src/main/java/org/apache/servicecomb/toolkit/common/MyersAlgorithm.java
@@ -35,8 +35,8 @@ public class MyersAlgorithm implements CompareAlgorithm {
public List<Comparison> compare(String source, String dest) {
if ((source == null) || (dest == null)) {
- LOGGER.error("source is {} and dest is {}", source, dest);
- throw new RuntimeException("source and dest must not be null");
+ LOGGER.error("Source is {} and dest is {}", source, dest);
+ throw new RuntimeException("Source and dest must not be null");
}
EditList diffList = new EditList();
diff --git a/common/src/test/java/org/apache/servicecomb/toolkit/common/FileUtilsTest.java b/common/src/test/java/org/apache/servicecomb/toolkit/common/FileUtilsTest.java
old mode 100644
new mode 100755
index 290a9df..533b65b
--- a/common/src/test/java/org/apache/servicecomb/toolkit/common/FileUtilsTest.java
+++ b/common/src/test/java/org/apache/servicecomb/toolkit/common/FileUtilsTest.java
@@ -35,7 +35,7 @@ public class FileUtilsTest {
try {
FileUtils.createDirectory(null);
} catch (IOException e) {
- assertEquals("path is null", e.getMessage());
+ assertEquals("Path is null", e.getMessage());
}
Path path;
@@ -52,7 +52,7 @@ public class FileUtilsTest {
try {
FileUtils.getFilesGroupByFilename(null);
} catch (IOException e) {
- assertEquals("path is null", e.getMessage());
+ assertEquals("Path is null", e.getMessage());
}
try {
diff --git a/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java b/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java
index 4a8ebbc..564adc0 100755
--- a/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java
+++ b/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java
@@ -126,7 +126,7 @@ public class TextCompareTest {
assertEquals(MyersAlgorithm.class, contractComparator.getAlgorithm().getClass());
contractComparator.splitPrint(bout);
} catch (RuntimeException e) {
- assertEquals("source and dest must not be null", e.getMessage());
+ assertEquals("Source and dest must not be null", e.getMessage());
}
}
}
diff --git a/contractgen/src/main/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGenerator.java b/contractgen/src/main/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGenerator.java
index 6bc01a5..bdfacb8 100755
--- a/contractgen/src/main/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGenerator.java
+++ b/contractgen/src/main/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGenerator.java
@@ -89,7 +89,7 @@ public class DefaultContractsGenerator implements ContractsGenerator {
}
@Override
- public boolean generate() throws RuntimeException {
+ public void generate() throws RuntimeException {
URL[] runtimeUrls = new URL[classpathUrls.size()];
for (int i = 0; i < classpathUrls.size(); i++) {
@@ -99,12 +99,12 @@ public class DefaultContractsGenerator implements ContractsGenerator {
try {
runtimeUrls[i] = new File(element).toURI().toURL();
} catch (MalformedURLException e) {
- throw new RuntimeException("wrong element in classpath", e);
+ throw new RuntimeException("Wrong element in classpath", e);
}
}
if (!checkConfig()) {
- return false;
+ throw new IllegalArgumentException("Cannot found configuration");
}
ImmediateClassLoader immediateClassLoader = new ImmediateClassLoader(runtimeUrls,
@@ -143,7 +143,6 @@ public class DefaultContractsGenerator implements ContractsGenerator {
} catch (IOException e) {
throw new RuntimeException(e);
}
- return true;
}
private boolean checkConfig() {
@@ -188,7 +187,7 @@ public class DefaultContractsGenerator implements ContractsGenerator {
return (Vector) classesField.get(classLoader);
}
} catch (Exception e) {
- throw new RuntimeException("cannot get class from ClassLoader " + classLoader.getClass());
+ throw new RuntimeException("Cannot get class from ClassLoader " + classLoader.getClass());
}
return new Vector<>();
}
diff --git a/contractgen/src/test/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGeneratorTest.java b/contractgen/src/test/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGeneratorTest.java
index c29555c..7f0850a 100644
--- a/contractgen/src/test/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGeneratorTest.java
+++ b/contractgen/src/test/java/org/apache/servicecomb/toolkit/contractgen/DefaultContractsGeneratorTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -85,7 +86,11 @@ public class DefaultContractsGeneratorTest {
DefaultContractsGenerator defaultContractsGenerator = new DefaultContractsGenerator();
defaultContractsGenerator.configure(config);
- assertTrue(defaultContractsGenerator.generate());
+ try {
+ defaultContractsGenerator.generate();
+ } catch (RuntimeException e) {
+ fail();
+ }
}
@Test
diff --git a/core/src/main/java/org/apache/servicecomb/toolkit/Generator.java b/core/src/main/java/org/apache/servicecomb/toolkit/Generator.java
index 7941d3a..0e54343 100755
--- a/core/src/main/java/org/apache/servicecomb/toolkit/Generator.java
+++ b/core/src/main/java/org/apache/servicecomb/toolkit/Generator.java
@@ -25,5 +25,5 @@ public interface Generator {
void configure(Map<String, Object> config);
- boolean generate();
+ void generate();
}
diff --git a/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java b/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
index 6110f0e..4277652 100755
--- a/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
+++ b/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
@@ -67,10 +67,10 @@ public class ContractsSwaggerUIGenerator implements DocGenerator {
}
@Override
- public boolean generate() {
+ public void generate() {
if (!checkConfig()) {
- return false;
+ throw new IllegalArgumentException("Cannot found configuration");
}
String swaggerUiHtml = null;
@@ -92,8 +92,6 @@ public class ContractsSwaggerUIGenerator implements DocGenerator {
} catch (IOException e) {
throw new RuntimeException(e);
}
-
- return true;
}
private String correctPath(String filepath) {
diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateMojo.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateMojo.java
index fa2635f..222166b 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateMojo.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateMojo.java
@@ -70,42 +70,42 @@ public class GenerateMojo extends AbstractMojo {
try {
FileUtils.createDirectory(contractOutput);
} catch (IOException e) {
- throw new RuntimeException("failed to generate contract.", e);
+ throw new RuntimeException("Failed to generate contract.", e);
}
GenerateUtil.generateContract(project, contractOutput, contractFileType, "default");
contractLocation = contractOutput;
if (Objects.requireNonNull(new File(contractOutput).listFiles()).length == 0) {
- LOGGER.info("no contract in the code");
+ LOGGER.info("No contract in the code");
return;
}
break;
case CONTRACT:
if (contractLocation == null) {
- throw new RuntimeException("invalid or not config contract location");
+ throw new RuntimeException("Invalid or not config contract location");
}
if (!new File(contractLocation).exists()) {
- throw new RuntimeException("contract path " + contractLocation + " is not exists");
+ throw new RuntimeException("Contract path " + contractLocation + " is not exists");
}
break;
default:
- throw new RuntimeException("not support source type " + sourceType);
+ throw new RuntimeException("Not support source type " + sourceType);
}
//generate microservice project
if (service == null) {
- LOGGER.info("no service configuration and do not generate code");
- return;
- }
- String codeOutput = outputDirectory + File.separator + "project";
- try {
- FileUtils.createDirectory(codeOutput);
- GenerateUtil.generateCode(service, contractLocation, codeOutput, "default");
- } catch (IOException e) {
- throw new RuntimeException("failed to generate code", e);
+ LOGGER.info("Cannot generate code without service configuration");
+ } else {
+ String codeOutput = outputDirectory + File.separator + "project";
+ try {
+ FileUtils.createDirectory(codeOutput);
+ GenerateUtil.generateCode(service, contractLocation, codeOutput, "default");
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to generate code", e);
+ }
}
//generate document
@@ -114,7 +114,7 @@ public class GenerateMojo extends AbstractMojo {
FileUtils.createDirectory(documentOutput);
GenerateUtil.generateDocument(contractLocation, documentOutput, "default");
} catch (IOException e) {
- throw new RuntimeException("failed to generate document", e);
+ throw new RuntimeException("Failed to generate document", e);
}
}
}
diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateUtil.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateUtil.java
index 905015a..4773077 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateUtil.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateUtil.java
@@ -50,7 +50,7 @@ public class GenerateUtil {
try {
contractConfig.put("classpathUrls", project.getRuntimeClasspathElements());
} catch (DependencyResolutionRequiredException e) {
- throw new RuntimeException("failed to get runtime class elements", e);
+ throw new RuntimeException("Failed to get runtime class elements", e);
}
contractConfig.put("outputDir", contractOutput);
contractConfig.put("contractFileType", contractFileType);
@@ -58,9 +58,8 @@ public class GenerateUtil {
// TODO: support users to add other getGenerator type soon
ContractsGenerator contractGenerator = GeneratorFactory.getGenerator(ContractsGenerator.class, type);
Objects.requireNonNull(contractGenerator).configure(contractConfig);
- if (!contractGenerator.generate()) {
- throw new RuntimeException("failed to generate contract by generator " + type);
- }
+
+ contractGenerator.generate();
}
public static void generateDocument(String contractLocation, String documentOutput, String type) throws IOException {
@@ -68,7 +67,7 @@ public class GenerateUtil {
// TODO: support users to add other getGenerator type soon
DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, type);
if (docGenerator == null) {
- throw new RuntimeException("not found document generator's implementation");
+ throw new RuntimeException("Cannot found document generator's implementation");
}
Files.walkFileTree(Paths.get(contractLocation), new SimpleFileVisitor<Path>() {
@@ -83,9 +82,7 @@ public class GenerateUtil {
.substring(0, file.toFile().getName().indexOf(".")));
docGenerator.configure(docGeneratorConfig);
- if (!docGenerator.generate()) {
- throw new RuntimeException("failed to generate document by generator " + type);
- }
+ docGenerator.generate();
return super.visitFile(file, attrs);
}
@@ -97,7 +94,7 @@ public class GenerateUtil {
CodeGenerator codeGenerator = GeneratorFactory.getGenerator(CodeGenerator.class, type);
if (codeGenerator == null) {
- throw new RuntimeException("not found code generator's implementation");
+ throw new RuntimeException("Cannot found code generator's implementation");
}
CodegenConfigurator configurator = new CodegenConfigurator();
@@ -120,18 +117,15 @@ public class GenerateUtil {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
configurator.setInputSpec(file.toFile().getCanonicalPath());
Objects.requireNonNull(codeGenerator).configure(Collections.singletonMap("configurator", configurator));
- if (!codeGenerator.generate()) {
- throw new RuntimeException("failed to generate code by generator " + type);
- }
+ codeGenerator.generate();
+
return super.visitFile(file, attrs);
}
});
} else {
configurator.setInputSpec(contractLocation);
Objects.requireNonNull(codeGenerator).configure(Collections.singletonMap("configurator", configurator));
- if (!codeGenerator.generate()) {
- throw new RuntimeException("failed to generate code by generator " + type);
- }
+ codeGenerator.generate();
}
}
}
diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/VerifyMojo.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/VerifyMojo.java
index 43d1b28..cf7c493 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/VerifyMojo.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/VerifyMojo.java
@@ -63,7 +63,7 @@ public class VerifyMojo extends AbstractMojo {
sourceContractPath = FileUtils.createTempDirectory("target/tmp-contract").toFile().getCanonicalPath();
GenerateUtil.generateContract(project, sourceContractPath, contractFileType,"default");
} catch (IOException e) {
- throw new RuntimeException("failed to generate contract from code.", e);
+ throw new RuntimeException("Failed to generate contract from code.", e);
}
break;
@@ -71,7 +71,7 @@ public class VerifyMojo extends AbstractMojo {
break;
default:
- throw new RuntimeException("not support source type " + sourceType);
+ throw new RuntimeException("Not support source type " + sourceType);
}
try {
@@ -85,15 +85,15 @@ public class VerifyMojo extends AbstractMojo {
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("Contract is not matched, difference is as follows");
LOGGER.info(destinationContractPath + "/" + contractName + " vs " + sourceContractPath + "/" + contractName);
contractComparator.splitPrintToScreen();
} else {
- LOGGER.info("succee, contract verification passed");
+ LOGGER.info("Succee, contract verification passed");
}
});
} catch (IOException e) {
- throw new RuntimeException("failed to verify contract", e);
+ throw new RuntimeException("Failed to verify contract", e);
}
}
}
diff --git a/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateMojoTest.java b/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateMojoTest.java
old mode 100644
new mode 100755
index 326c438..de47ebb
--- a/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateMojoTest.java
+++ b/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateMojoTest.java
@@ -120,6 +120,7 @@ public class GenerateMojoTest {
rule.setVariableValueToObject(generateMojo, "outputDirectory", outputDirectory);
rule.setVariableValueToObject(generateMojo, "contractFileType", "yaml");
rule.setVariableValueToObject(generateMojo, "documentType", "html");
+ rule.setVariableValueToObject(generateMojo, "service", new ServiceConfig());
generateMojo.execute();
@@ -140,7 +141,7 @@ public class GenerateMojoTest {
generateMojo.execute();
} catch (RuntimeException e) {
- assertEquals("invalid or not config contract location", e.getMessage());
+ assertEquals("Invalid or not config contract location", e.getMessage());
isSuccessful = true;
}
assertTrue(isSuccessful);
diff --git a/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateUtilTest.java b/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateUtilTest.java
old mode 100644
new mode 100755
index 07d8273..69fcdf8
--- a/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateUtilTest.java
+++ b/toolkit-maven-plugin/src/test/java/org/apache/servicecomb/toolkit/plugin/GenerateUtilTest.java
@@ -23,14 +23,11 @@ import static org.apache.servicecomb.toolkit.plugin.GenerateUtil.generateDocumen
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.fail;
-import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Objects;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -60,7 +57,7 @@ public class GenerateUtilTest {
try {
generateContract(project, contractOutput, "yaml", "default");
} catch (RuntimeException e) {
- assertEquals("failed to get runtime class elements", e.getMessage());
+ assertEquals("Failed to get runtime class elements", e.getMessage());
return;
}
@@ -79,7 +76,7 @@ public class GenerateUtilTest {
try {
generateCode(service, contractLocation.getCanonicalPath(), projectOutput, "invalidType");
} catch (RuntimeException e) {
- assertEquals("not found code generator's implementation", e.getMessage());
+ assertEquals("Cannot found code generator's implementation", e.getMessage());
return;
}
@@ -97,7 +94,7 @@ public class GenerateUtilTest {
try {
generateDocument(contractLocation.getCanonicalPath(), codeOutput, "invalidType");
} catch (RuntimeException e) {
- assertEquals("not found document generator's implementation", e.getMessage());
+ assertEquals("Cannot found document generator's implementation", e.getMessage());
return;
}