diff options
Diffstat (limited to 'model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java')
-rw-r--r-- | model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java index bf63e6db7..36ce4e438 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -23,11 +24,9 @@ package org.onap.policy.apex.model.basicmodel.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.net.URL; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxModel; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.ApexDao; import org.onap.policy.apex.model.basicmodel.dao.ApexDaoFactory; import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter; @@ -87,7 +86,7 @@ public class TestApexModel<M extends AxModel> { public final void testApexModelWriteReadXml() throws ApexException { LOGGER.debug("running testApexModelWriteReadXML . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); // Write the file to disk File xmlFile; @@ -105,8 +104,8 @@ public class TestApexModel<M extends AxModel> { final ApexModelReader<M> modelReader = new ApexModelReader<>(rootModelClass); try { - final URL apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath()); - final M fileModel = modelReader.read(apexModelUrl.openStream()); + final var apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath()); + final var fileModel = modelReader.read(apexModelUrl.openStream()); checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath()); } catch (final Exception e) { LOGGER.warn(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e); @@ -118,10 +117,10 @@ public class TestApexModel<M extends AxModel> { modelWriter.getCDataFieldSet().add("logic"); modelWriter.getCDataFieldSet().add("uiLogic"); - final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); + final var baOutputStream = new ByteArrayOutputStream(); modelWriter.write(model, baOutputStream); - final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); - final M byteArrayModel = modelReader.read(baInputStream); + final var baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); + final var byteArrayModel = modelReader.read(baInputStream); checkModelEquality(model, byteArrayModel, "test model does not equal XML marshalled and unmarshalled model"); @@ -136,7 +135,7 @@ public class TestApexModel<M extends AxModel> { public final void testApexModelWriteReadJson() throws ApexException { LOGGER.debug("running testApexModelWriteReadJSON . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); // Write the file to disk File jsonFile; @@ -153,8 +152,8 @@ public class TestApexModel<M extends AxModel> { final ApexModelReader<M> modelReader = new ApexModelReader<>(rootModelClass); try { - final URL apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath()); - final M fileModel = modelReader.read(apexModelUrl.openStream()); + final var apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath()); + final var fileModel = modelReader.read(apexModelUrl.openStream()); checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath()); } catch (final Exception e) { LOGGER.warn(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e); @@ -164,11 +163,11 @@ public class TestApexModel<M extends AxModel> { final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass); modelWriter.setJsonOutput(true); - final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); + final var baOutputStream = new ByteArrayOutputStream(); modelWriter.write(model, baOutputStream); - final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); - final M byteArrayModel = modelReader.read(baInputStream); - + final var baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); + final var byteArrayModel = modelReader.read(baInputStream); + checkModelEquality(model, byteArrayModel, "test model does not equal JSON marshalled and unmarshalled model"); LOGGER.debug("ran testApexModelWriteReadJSON"); @@ -183,13 +182,13 @@ public class TestApexModel<M extends AxModel> { public final void testApexModelWriteReadJpa(final DaoParameters daoParameters) throws ApexException { LOGGER.debug("running testApexModelWriteReadJPA . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); - final ApexDao apexDao = new ApexDaoFactory().createApexDao(daoParameters); + final var apexDao = new ApexDaoFactory().createApexDao(daoParameters); apexDao.init(daoParameters); apexDao.create(model); - final M dbJpaModel = apexDao.get(rootModelClass, model.getKey()); + final var dbJpaModel = apexDao.get(rootModelClass, model.getKey()); apexDao.close(); checkModelEquality(model, dbJpaModel, "test model does not equal model written and read using generic JPA"); @@ -206,7 +205,7 @@ public class TestApexModel<M extends AxModel> { public final AxValidationResult testApexModelValid() throws ApexException { LOGGER.debug("running testApexModelVaid . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (!result.isValid()) { @@ -228,7 +227,7 @@ public class TestApexModel<M extends AxModel> { public final AxValidationResult testApexModelVaidateMalstructured() throws ApexException { LOGGER.debug("running testApexModelVaidateMalstructured . . ."); - final M model = modelCreator.getMalstructuredModel(); + final var model = modelCreator.getMalstructuredModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (result.isValid()) { @@ -250,7 +249,7 @@ public class TestApexModel<M extends AxModel> { public final AxValidationResult testApexModelVaidateObservation() throws ApexException { LOGGER.debug("running testApexModelVaidateObservation . . ."); - final M model = modelCreator.getObservationModel(); + final var model = modelCreator.getObservationModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (!result.isValid()) { @@ -277,7 +276,7 @@ public class TestApexModel<M extends AxModel> { public final AxValidationResult testApexModelVaidateWarning() throws ApexException { LOGGER.debug("running testApexModelVaidateWarning . . ."); - final M model = modelCreator.getWarningModel(); + final var model = modelCreator.getWarningModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (!result.isValid()) { @@ -304,7 +303,7 @@ public class TestApexModel<M extends AxModel> { public final AxValidationResult testApexModelVaidateInvalidModel() throws ApexException { LOGGER.debug("running testApexModelVaidateInvalidModel . . ."); - final M model = modelCreator.getInvalidModel(); + final var model = modelCreator.getInvalidModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (result.isValid()) { @@ -319,7 +318,7 @@ public class TestApexModel<M extends AxModel> { /** * Check if two models are equal. - * + * * @param leftModel the left model * @param rightModel the right model * @param errorMessage the error message to output on inequality |