summaryrefslogtreecommitdiffstats
path: root/aai-schema-gen/src/test/java
diff options
context:
space:
mode:
authorKeong Lim <keong.lim@huawei.com>2019-03-22 18:03:54 +1100
committerKeong Lim <keong.lim@huawei.com>2019-03-26 15:30:42 +1100
commit79e9db7096b53a81a03c984283cb7307287ba811 (patch)
tree4cfd52c61f74ebde786eef1f700fd9eeb515f2d8 /aai-schema-gen/src/test/java
parent85a4c19f32264bce094e8e9a35adf08e86cdd204 (diff)
AAI-2279 coverage of schema-service/aai-schema-gen
Add tests for schemagen/swagger/Api.java Add tests for schemagen/swagger/Definition.java Tweak schemagen/swagger/Api.java to get more coverage from tests Tweak schemagen/swagger/Definition.java to get more coverage from tests Commit a json file that is generated during test runs Tweak onap-java-formatter to pass checkstyle audit Change-Id: I1f2e9a36b7263818aa5030dcd8ec9b050d046fb1 Issue-ID: AAI-2279 Signed-off-by: Keong Lim <keong.lim@huawei.com>
Diffstat (limited to 'aai-schema-gen/src/test/java')
-rw-r--r--aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbResponseTest.java84
-rw-r--r--aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbTest.java123
-rw-r--r--aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionPropertyTest.java108
-rw-r--r--aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionTest.java100
4 files changed, 415 insertions, 0 deletions
diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbResponseTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbResponseTest.java
new file mode 100644
index 0000000..2a39149
--- /dev/null
+++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbResponseTest.java
@@ -0,0 +1,84 @@
+/*
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.schemagen.swagger;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ApiHttpVerbResponseTest {
+ Api.HttpVerb.Response theResponse = null;
+ String responseCode;
+ String description;
+ String result;
+
+ /**
+ * Parameters for the test cases all following same pattern.
+ */
+ @Parameters
+ public static Collection<String[]> testConditions() {
+ String inputs[][] = {{"200", "OK", "Response{responseCode='200', description='OK'}"},
+ {"400", "Bad Request", "Response{responseCode='400', description='Bad Request'}"},
+ {"500", "Internal Server Error",
+ "Response{responseCode='500', description='Internal Server Error'}"},
+ {"fake", "random message",
+ "Response{responseCode='fake', description='random message'}"}};
+ return (Arrays.asList(inputs));
+ }
+
+ /**
+ * Constructor for the test cases all following same pattern.
+ */
+ public ApiHttpVerbResponseTest(String responseCode, String description, String result) {
+ super();
+ this.responseCode = responseCode;
+ this.description = description;
+ this.result = result;
+ }
+
+ /**
+ * Initialise the test object.
+ */
+ @Before
+ public void setUp() throws Exception {
+ theResponse = new Api.HttpVerb.Response();
+ }
+
+ /**
+ * Perform the test on the test object.
+ */
+ @Test
+ public void testApiHttpVerbResponse() {
+ theResponse.setResponseCode(this.responseCode);
+ theResponse.setDescription(this.description);
+ assertThat(theResponse.toString(), is(this.result));
+ }
+
+}
diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbTest.java
new file mode 100644
index 0000000..c714d82
--- /dev/null
+++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbTest.java
@@ -0,0 +1,123 @@
+/*
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.schemagen.swagger;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ApiHttpVerbTest {
+ Api.HttpVerb theVerb = null;
+ List<String> tags;
+ String type;
+ String summary;
+ String operationId;
+ List<String> consumes;
+ List<String> produces;
+ String result;
+
+ /**
+ * Parameters for the test cases all following same pattern.
+ */
+ @Parameters
+ public static Collection<String[]> testConditions() {
+ String inputs[][] = {{"tag1,tag2", "typeA", "summaryB", "operationC", "consumesD,consumesE",
+ "producesF,producesG",
+ "HttpVerb{tags=[tag1, tag2], type='typeA', summary='summaryB', operationId='operationC', consumes=[consumesD, consumesE], produces=[producesF, producesG], responses=[], parameters=[]}"},
+ {"tag11,tag22", "typeAA", "summaryBB", "operationCC", "consumesDD,consumesEE",
+ "producesFF,producesGG",
+ "HttpVerb{tags=[tag11, tag22], type='typeAA', summary='summaryBB', operationId='operationCC', consumes=[consumesDD, consumesEE], produces=[producesFF, producesGG], responses=[], parameters=[]}"}};
+ return (Arrays.asList(inputs));
+ }
+
+ /**
+ * Constructor for the test cases all following same pattern.
+ */
+ public ApiHttpVerbTest(String tags, String type, String summary, String operationId,
+ String consumes, String produces, String result) {
+ super();
+ this.tags = Arrays.asList(tags.split(","));
+ this.type = type;
+ this.summary = summary;
+ this.operationId = operationId;
+ this.consumes = Arrays.asList(consumes.split(","));
+ this.produces = Arrays.asList(produces.split(","));
+ this.result = result;
+
+ }
+
+ /**
+ * Initialise the test object.
+ */
+ @Before
+ public void setUp() throws Exception {
+ theVerb = new Api.HttpVerb();
+ }
+
+ /**
+ * Perform the test on the test object.
+ */
+ @Test
+ public void testApiHttpVerb() {
+ theVerb.setTags(this.tags);
+ theVerb.setType(this.type);
+ theVerb.setSummary(this.summary);
+ theVerb.setOperationId(this.operationId);
+ theVerb.setConsumes(this.consumes);
+ theVerb.setProduces(this.produces);
+
+ // other stuff that can be set but not necessarily
+ // included in the toString() output
+ theVerb.setConsumerEnabled(true);
+
+ List<Api.HttpVerb.Response> tmpList1 = new ArrayList<Api.HttpVerb.Response>();
+ theVerb.setResponses(tmpList1);
+
+ List<Map<String, Object>> tmpList2 = new ArrayList<Map<String, Object>>();
+ theVerb.setParameters(tmpList2);
+
+ Map<String, Object> tmpMap1 = new HashMap<String, Object>();
+ theVerb.setBodyParameters(tmpMap1);
+ theVerb.setBodyParametersEnabled(true);
+ theVerb.setParametersEnabled(true);
+ theVerb.setSchemaLink("");
+ theVerb.setSchemaType("");
+ theVerb.setHasReturnSchema(true);
+ theVerb.setReturnSchemaLink("");
+ theVerb.setReturnSchemaObject("");
+
+ assertThat(theVerb.toString(), is(this.result));
+ }
+
+}
diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionPropertyTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionPropertyTest.java
new file mode 100644
index 0000000..fef3344
--- /dev/null
+++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionPropertyTest.java
@@ -0,0 +1,108 @@
+/*
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.schemagen.swagger;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class DefinitionPropertyTest {
+ Definition.Property theProperty = null;
+ String propertyName;
+ String propertyType;
+ String propertyReference;
+ String result;
+
+ /**
+ * Parameters for the test cases all following same pattern.
+ */
+ @Parameters
+ public static Collection<String[]> testConditions() {
+ String inputs[][] = {
+ {"name1", "type1", "ref1",
+ "Property{propertyName='name1', propertyType='type1', propertyReference='ref1'}"},
+ {"name2", "type2", "ref2",
+ "Property{propertyName='name2', propertyType='type2', propertyReference='ref2'}"},
+ {"fake", "random", "bluff",
+ "Property{propertyName='fake', propertyType='random', propertyReference='bluff'}"}};
+ return (Arrays.asList(inputs));
+ }
+
+ /**
+ * Constructor for the test cases all following same pattern.
+ */
+ public DefinitionPropertyTest(String propertyName, String propertyType,
+ String propertyReference, String result) {
+ super();
+ this.propertyName = propertyName;
+ this.propertyType = propertyType;
+ this.propertyReference = propertyReference;
+ this.result = result;
+ }
+
+ /**
+ * Initialise the test object.
+ */
+ @Before
+ public void setUp() throws Exception {
+ theProperty = new Definition.Property();
+ }
+
+ /**
+ * Perform the test on the test object.
+ */
+ @Test
+ public void testDefinitionProperty() {
+ theProperty.setPropertyName(this.propertyName);
+ theProperty.setPropertyType(this.propertyType);
+ theProperty.setPropertyReference(this.propertyReference);
+ assertThat(theProperty.toString(), is(this.result));
+
+ // other stuff that can be set but not necessarily
+ // included in the toString() output
+ theProperty.setHasType(true);
+ assertThat(theProperty.isHasType(), is(true));
+
+ theProperty.setRequired(true);
+ assertThat(theProperty.isRequired(), is(true));
+
+ theProperty.setHasPropertyReference(true);
+ assertThat(theProperty.isHasPropertyReference(), is(true));
+
+ theProperty.setPropertyReferenceObjectName("someName");
+ assertThat(theProperty.getPropertyReferenceObjectName(), is("someName"));
+
+ theProperty.setPropertyDescription("some description");
+ assertThat(theProperty.getPropertyDescription(), is("some description"));
+
+ theProperty.setHasPropertyDescription(true);
+ assertThat(theProperty.isHasPropertyDescription(), is(true));
+ }
+}
diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionTest.java
new file mode 100644
index 0000000..3a53019
--- /dev/null
+++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionTest.java
@@ -0,0 +1,100 @@
+/*
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.schemagen.swagger;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class DefinitionTest {
+ Definition theDefinition = null;
+ String definitionName;
+ String definitionDescription;
+ String result;
+
+ /**
+ * Parameters for the test cases all following same pattern.
+ */
+ @Parameters
+ public static Collection<String[]> testConditions() {
+ String inputs[][] = {
+ {"name1", "desc1",
+ "Definition{definitionName='name1', definitionDescription='desc1', propertyList=[]}"},
+ {"name2", "desc2",
+ "Definition{definitionName='name2', definitionDescription='desc2', propertyList=[]}"},
+ {"fake", "random",
+ "Definition{definitionName='fake', definitionDescription='random', propertyList=[]}"}};
+ return (Arrays.asList(inputs));
+ }
+
+ /**
+ * Constructor for the test cases all following same pattern.
+ */
+ public DefinitionTest(String definitionName, String definitionDescription, String result) {
+ super();
+ this.definitionName = definitionName;
+ this.definitionDescription = definitionDescription;
+ this.result = result;
+ }
+
+ /**
+ * Initialise the test object.
+ */
+ @Before
+ public void setUp() throws Exception {
+ theDefinition = new Definition();
+ }
+
+ /**
+ * Perform the test on the test object.
+ */
+ @Test
+ public void testDefinitionProperty() {
+ theDefinition.setDefinitionName(this.definitionName);
+ theDefinition.setDefinitionDescription(this.definitionDescription);
+
+ List<Definition.Property> tmpList1 = new ArrayList<Definition.Property>();
+ theDefinition.setPropertyList(tmpList1);
+ assertThat(theDefinition.toString(), is(this.result));
+
+ // other stuff that can be set but not necessarily
+ // included in the toString() output
+ theDefinition.setHasDescription(true);
+ assertThat(theDefinition.isHasDescription(), is(true));
+
+ theDefinition.setSchemaPropertyList(tmpList1);
+ assertThat(theDefinition.getSchemaPropertyList(), is(tmpList1));
+
+ theDefinition.setRegularPropertyList(tmpList1);
+ assertThat(theDefinition.getRegularPropertyList(), is(tmpList1));
+ }
+}