diff options
8 files changed, 489 insertions, 48 deletions
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java index 717b710..a3adcd8 100644 --- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java +++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -38,23 +38,23 @@ public class Api { this.httpMethods = httpMethods; } - public String getTag(){ + public String getTag() { - if(this.tag != null){ + if (this.tag != null) { return this.tag; } - if(this.httpMethods != null){ - if(this.httpMethods.size() != 0){ - if(this.httpMethods.get(0).getTags() != null){ - if(this.httpMethods.get(0).getTags().size() != 0){ + if (this.httpMethods != null) { + if (this.httpMethods.size() != 0) { + if (this.httpMethods.get(0).getTags() != null) { + if (this.httpMethods.get(0).getTags().size() != 0) { this.tag = this.httpMethods.get(0).getTags().get(0); } } } } - if(this.tag == null){ + if (this.tag == null) { this.tag = ""; } @@ -63,10 +63,7 @@ public class Api { @Override public String toString() { - return "Api{" + - "path='" + path + '\'' + - ", httpMethods=" + httpMethods + - '}'; + return "Api{" + "path='" + path + '\'' + ", httpMethods=" + httpMethods + '}'; } public void setPath(String path) { @@ -77,9 +74,9 @@ public class Api { return this.path; } - public String getOperation(){ + public String getOperation() { - if(this.path != null){ + if (this.path != null) { return this.path.replaceAll("[^a-zA-Z0-9\\-]", "-") + "-"; } @@ -122,7 +119,7 @@ public class Api { private String returnSchemaObject; - public void setConsumerEnabled(boolean consumerEnabled){ + public void setConsumerEnabled(boolean consumerEnabled) { this.consumerEnabled = consumerEnabled; } @@ -130,7 +127,6 @@ public class Api { return consumerEnabled; } - public List<String> getTags() { return tags; } @@ -197,16 +193,10 @@ public class Api { @Override public String toString() { - return "HttpVerb{" + - "tags=" + tags + - ", type='" + type + '\'' + - ", summary='" + summary + '\'' + - ", operationId='" + operationId + '\'' + - ", consumes=" + consumes + - ", produces=" + produces + - ", responses=" + responses + - ", parameters=" + parameters + - '}'; + return "HttpVerb{" + "tags=" + getTags() + ", type='" + getType() + '\'' + ", summary='" + + getSummary() + '\'' + ", operationId='" + getOperationId() + '\'' + ", consumes=" + + getConsumes() + ", produces=" + getProduces() + ", responses=" + getResponses() + + ", parameters=" + getParameters() + '}'; } public void setParametersEnabled(boolean b) { @@ -220,8 +210,9 @@ public class Api { public boolean isBodyParametersEnabled() { return bodyParametersEnabled; } + public boolean isOpNotPatch() { - return type.equalsIgnoreCase("patch") ? false : true; + return type.equalsIgnoreCase("patch") ? false : true; } public void setBodyParametersEnabled(boolean bodyParametersEnabled) { @@ -282,7 +273,7 @@ public class Api { private String description; - private String version; + private String version; public String getResponseCode() { return responseCode; @@ -302,15 +293,13 @@ public class Api { @Override public String toString() { - return "Response{" + - "responseCode='" + responseCode + '\'' + - ", description='" + description + '\'' + - '}'; + return "Response{" + "responseCode='" + getResponseCode() + '\'' + ", description='" + + getDescription() + '\'' + '}'; } - public void setVersion(String version) { - this.version = version; - } + public void setVersion(String version) { + this.version = version; + } } } diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java index 4a52020..9df9842 100644 --- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java +++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemagen.swagger; import java.util.List; @@ -61,11 +62,9 @@ public class Definition { @Override public String toString() { - return "Definition{" + - "definitionName='" + definitionName + '\'' + - ", definitionDescription='" + definitionDescription + '\'' + - ", propertyList=" + propertyList + - '}'; + return "Definition{" + "definitionName='" + getDefinitionName() + '\'' + + ", definitionDescription='" + getDefinitionDescription() + '\'' + ", propertyList=" + + getPropertyList() + '}'; } public boolean isHasDescription() { @@ -112,7 +111,8 @@ public class Definition { private boolean hasPropertyReference; - public Property(){} + public Property() { + } public String getPropertyName() { return propertyName; @@ -140,11 +140,9 @@ public class Definition { @Override public String toString() { - return "Property{" + - "propertyName='" + propertyName + '\'' + - ", propertyType='" + propertyType + '\'' + - ", propertyReference='" + propertyReference + '\'' + - '}'; + return "Property{" + "propertyName='" + getPropertyName() + '\'' + ", propertyType='" + + getPropertyType() + '\'' + ", propertyReference='" + getPropertyReference() + '\'' + + '}'; } public boolean isHasType() { 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)); + } +} diff --git a/aai-schema-gen/src/test/resources/dbedgerules/EdgeDescriptionRules_test.json b/aai-schema-gen/src/test/resources/dbedgerules/EdgeDescriptionRules_test.json new file mode 100644 index 0000000..c25f1fb --- /dev/null +++ b/aai-schema-gen/src/test/resources/dbedgerules/EdgeDescriptionRules_test.json @@ -0,0 +1,39 @@ +{ + "rules": [ + { + "from": "service-subscription", + "to": "customer", + "label": "org.onap.relationships.inventory.BelongsTo", + "direction": "OUT", + "multiplicity": "MANY2ONE", + "contains-other-v": "!${direction}", + "delete-other-v": "!${direction}", + "prevent-delete": "NONE", + "default": "true", + "description":"" + }, + { + "from": "service-instance", + "to": "service-subscription", + "label": "org.onap.relationships.inventory.BelongsTo", + "direction": "OUT", + "multiplicity": "MANY2ONE", + "contains-other-v": "!${direction}", + "delete-other-v": "!${direction}", + "prevent-delete": "NONE", + "default": "true", + "description":"" + }, + { + "from": "service-subscription", + "to": "tenant", + "label": "org.onap.relationships.inventory.Uses", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"" + } ] +} diff --git a/onap-java-formatter.xml b/onap-java-formatter.xml index 920d37b..2e34b9c 100644 --- a/onap-java-formatter.xml +++ b/onap-java-formatter.xml @@ -40,7 +40,7 @@ <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="0"/> <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="1"/> <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/> <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="2"/> <setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> |