summaryrefslogtreecommitdiffstats
path: root/model/basic-model/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'model/basic-model/src/test')
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java7
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java15
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java77
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java262
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java34
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java77
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java8
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java29
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java108
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java95
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java89
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java8
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java24
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java42
-rw-r--r--model/basic-model/src/test/resources/META-INF/persistence.xml43
15 files changed, 98 insertions, 820 deletions
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
index d066d674c..0c7edee28 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,10 +65,11 @@ public class AxKeyInfoTest {
assertEquals(testKeyInfo, testKeyInfo); // NOSONAR
assertEquals(testKeyInfo, clonedReferenceKey);
assertNotNull(testKeyInfo);
- assertNotEquals(testKeyInfo, (Object) new AxArtifactKey());
+ Object differentKeyType = new AxArtifactKey();
+ assertNotEquals(testKeyInfo, differentKeyType);
assertNotEquals(testKeyInfo, new AxKeyInfo(new AxArtifactKey()));
assertNotEquals(testKeyInfo, new AxKeyInfo(key, UUID.randomUUID(), "Some Description"));
- assertNotEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Some Description"));
+ assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Some Other Description"));
assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Key Description"));
assertEquals(0, testKeyInfo.compareTo(testKeyInfo));
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
index 2407dab38..2b16e89ed 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,24 +23,11 @@ package org.onap.policy.apex.model.basicmodel.concepts;
import java.util.Arrays;
import java.util.List;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
-
-@Entity
-@Table(name = "TestEntity")
public class DummyEntity extends AxConcept {
private static final long serialVersionUID = -2962570563281067894L;
- @EmbeddedId()
- @XmlElement(name = "key", required = true)
- @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
protected AxReferenceKey key;
-
private double doubleValue;
public DummyEntity() {
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java
deleted file mode 100644
index 6f9bef83d..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 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=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.dao;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import java.util.Properties;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner;
-import org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String;
-
-public class DaoMiscTest {
-
- @Test
- public void testUuid2StringMopUp() {
- final Uuid2String uuid2String = new Uuid2String();
- assertEquals("", uuid2String.convertToDatabaseColumn(null));
- }
-
- @Test
- public void testCDataConditionerMopUp() {
- assertNull(CDataConditioner.clean(null));
- }
-
- @Test
- public void testDaoFactory() {
- final DaoParameters daoParameters = new DaoParameters();
-
- daoParameters.setPluginClass("somewhere.over.the.rainbow");
- assertThatThrownBy(() -> new ApexDaoFactory().createApexDao(daoParameters))
- .hasMessage("Apex DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"");
- daoParameters.setPluginClass("java.lang.String");
- assertThatThrownBy(() -> new ApexDaoFactory().createApexDao(daoParameters))
- .hasMessage("Specified Apex DAO plugin class \"java.lang.String\" "
- + "does not implement the ApexDao interface");
- }
-
- @Test
- public void testDaoParameters() {
- final DaoParameters pars = new DaoParameters();
- pars.setJdbcProperties(new Properties());
- assertEquals(0, pars.getJdbcProperties().size());
-
- pars.setJdbcProperty("name", "Dorothy");
- assertEquals("Dorothy", pars.getJdbcProperty("name"));
-
- pars.setPersistenceUnit("Kansas");
- assertEquals("Kansas", pars.getPersistenceUnit());
-
- pars.setPluginClass("somewhere.over.the.rainbow");
- assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
-
- assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
- + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());
- }
-}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java
deleted file mode 100644
index e584085c3..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 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=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.dao;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.UUID;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-import org.onap.policy.apex.model.basicmodel.concepts.DummyEntity;
-
-/**
- * JUnit test class.
- */
-public class EntityTest {
- private ApexDao apexDao;
-
- @Test
- public void testEntityTestSanity() throws ApexException {
- final DaoParameters daoParameters = new DaoParameters();
-
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
-
- assertThatThrownBy(() -> apexDao.init(null))
- .hasMessage("Apex persistence unit parameter not set");
- assertThatThrownBy(() -> apexDao.init(daoParameters))
- .hasMessage("Apex persistence unit parameter not set");
- daoParameters.setPluginClass("somewhere.over.the.rainbow");
- daoParameters.setPersistenceUnit("Dorothy");
- assertThatThrownBy(() -> apexDao.init(daoParameters))
- .hasMessage("Creation of Apex persistence unit \"Dorothy\" failed");
- assertThatThrownBy(() -> apexDao.create(new AxArtifactKey()))
- .hasMessage("Apex DAO has not been initialized");
- apexDao.close();
- }
-
- @Test
- public void testEntityTestAllOpsJpa() throws ApexException {
- final DaoParameters daoParameters = new DaoParameters();
- daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
- daoParameters.setPersistenceUnit("DaoTest");
-
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
- apexDao.init(daoParameters);
-
- testAllOps();
- apexDao.close();
- }
-
- @Test
- public void testEntityTestBadVals() throws ApexException {
- final DaoParameters daoParameters = new DaoParameters();
- assertNotNull(daoParameters);
- daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
- assertEquals("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao", daoParameters.getPluginClass());
- daoParameters.setPersistenceUnit("DaoTest");
- assertEquals("DaoTest", daoParameters.getPersistenceUnit());
-
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
- apexDao.init(daoParameters);
-
- final AxArtifactKey nullKey = null;
- final AxReferenceKey nullRefKey = null;
- final List<AxArtifactKey> nullKeyList = null;
- final List<AxArtifactKey> emptyKeyList = new ArrayList<>();
- final List<AxReferenceKey> nullRKeyList = null;
- final List<AxReferenceKey> emptyRKeyList = new ArrayList<>();
-
- apexDao.create(nullKey);
- apexDao.createCollection(nullKeyList);
- apexDao.createCollection(emptyKeyList);
-
- apexDao.delete(nullKey);
- apexDao.deleteCollection(nullKeyList);
- apexDao.deleteCollection(emptyKeyList);
- apexDao.delete(AxArtifactKey.class, nullKey);
- apexDao.delete(AxReferenceKey.class, nullRefKey);
- apexDao.deleteByArtifactKey(AxArtifactKey.class, nullKeyList);
- apexDao.deleteByArtifactKey(AxArtifactKey.class, emptyKeyList);
- apexDao.deleteByReferenceKey(AxReferenceKey.class, nullRKeyList);
- apexDao.deleteByReferenceKey(AxReferenceKey.class, emptyRKeyList);
-
- apexDao.get(null, nullKey);
- apexDao.get(null, nullRefKey);
- apexDao.getAll(null);
- apexDao.getAll(null, nullKey);
- apexDao.getArtifact(null, nullKey);
- apexDao.getArtifact(AxArtifactKey.class, nullKey);
- apexDao.getArtifact(null, nullRefKey);
- apexDao.getArtifact(AxReferenceKey.class, nullRefKey);
- apexDao.size(null);
-
- apexDao.close();
- }
-
- private void testAllOps() {
- final AxArtifactKey aKey0 = new AxArtifactKey("A-KEY0", "0.0.1");
- final AxArtifactKey aKey1 = new AxArtifactKey("A-KEY1", "0.0.1");
- final AxArtifactKey aKey2 = new AxArtifactKey("A-KEY2", "0.0.1");
- final AxKeyInfo keyInfo0 = new AxKeyInfo(aKey0, UUID.fromString("00000000-0000-0000-0000-000000000000"),
- "key description 0");
- final AxKeyInfo keyInfo1 = new AxKeyInfo(aKey1, UUID.fromString("00000000-0000-0000-0000-000000000001"),
- "key description 1");
- final AxKeyInfo keyInfo2 = new AxKeyInfo(aKey2, UUID.fromString("00000000-0000-0000-0000-000000000002"),
- "key description 2");
-
- apexDao.create(keyInfo0);
-
- final AxKeyInfo keyInfoBack0 = apexDao.get(AxKeyInfo.class, aKey0);
- assertEquals(keyInfo0, keyInfoBack0);
-
- final AxKeyInfo keyInfoBackNull = apexDao.get(AxKeyInfo.class, AxArtifactKey.getNullKey());
- assertNull(keyInfoBackNull);
-
- final AxKeyInfo keyInfoBack1 = apexDao.getArtifact(AxKeyInfo.class, aKey0);
- assertEquals(keyInfoBack0, keyInfoBack1);
-
- final AxKeyInfo keyInfoBack2 = apexDao.getArtifact(AxKeyInfo.class, new AxArtifactKey("A-KEY3", "0.0.1"));
- assertNull(keyInfoBack2);
-
- final Set<AxKeyInfo> keyInfoSetIn = new TreeSet<AxKeyInfo>();
- keyInfoSetIn.add(keyInfo1);
- keyInfoSetIn.add(keyInfo2);
-
- apexDao.createCollection(keyInfoSetIn);
-
- Set<AxKeyInfo> keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
-
- keyInfoSetIn.add(keyInfo0);
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.delete(keyInfo1);
- keyInfoSetIn.remove(keyInfo1);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.deleteCollection(keyInfoSetIn);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(0, keyInfoSetOut.size());
-
- keyInfoSetIn.add(keyInfo0);
- keyInfoSetIn.add(keyInfo1);
- keyInfoSetIn.add(keyInfo0);
- apexDao.createCollection(keyInfoSetIn);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.delete(AxKeyInfo.class, aKey0);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(2, keyInfoSetOut.size());
- assertEquals(2, apexDao.size(AxKeyInfo.class));
-
- final Set<AxArtifactKey> keySetIn = new TreeSet<AxArtifactKey>();
- keySetIn.add(aKey1);
- keySetIn.add(aKey2);
-
- final int deletedCount = apexDao.deleteByArtifactKey(AxKeyInfo.class, keySetIn);
- assertEquals(2, deletedCount);
-
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(0, keyInfoSetOut.size());
-
- keyInfoSetIn.add(keyInfo0);
- keyInfoSetIn.add(keyInfo1);
- keyInfoSetIn.add(keyInfo0);
- apexDao.createCollection(keyInfoSetIn);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.deleteAll(AxKeyInfo.class);
- assertEquals(0, apexDao.size(AxKeyInfo.class));
-
- final AxArtifactKey owner0Key = new AxArtifactKey("Owner0", "0.0.1");
- final AxArtifactKey owner1Key = new AxArtifactKey("Owner1", "0.0.1");
- final AxArtifactKey owner2Key = new AxArtifactKey("Owner2", "0.0.1");
- final AxArtifactKey owner3Key = new AxArtifactKey("Owner3", "0.0.1");
- final AxArtifactKey owner4Key = new AxArtifactKey("Owner4", "0.0.1");
- final AxArtifactKey owner5Key = new AxArtifactKey("Owner5", "0.0.1");
-
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity0"), 100.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity1"), 101.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity2"), 102.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity3"), 103.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity4"), 104.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity5"), 105.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity6"), 106.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity7"), 107.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner2Key, "Entity8"), 108.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner2Key, "Entity9"), 109.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner3Key, "EntityA"), 110.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner4Key, "EntityB"), 111.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityC"), 112.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityD"), 113.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityE"), 114.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityF"), 115.0));
-
- TreeSet<DummyEntity> testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class));
- assertEquals(16, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner0Key));
- assertEquals(5, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner1Key));
- assertEquals(3, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner2Key));
- assertEquals(2, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner3Key));
- assertEquals(1, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner4Key));
- assertEquals(1, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner5Key));
- assertEquals(4, testEntitySetOut.size());
-
- assertNotNull(apexDao.get(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0")));
- assertNotNull(apexDao.getArtifact(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0")));
- assertNull(apexDao.get(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity1000")));
- assertNull(apexDao.getArtifact(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity1000")));
- apexDao.delete(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0"));
-
- final Set<AxReferenceKey> rKeySetIn = new TreeSet<AxReferenceKey>();
- rKeySetIn.add(new AxReferenceKey(owner4Key, "EntityB"));
- rKeySetIn.add(new AxReferenceKey(owner5Key, "EntityD"));
-
- final int deletedRCount = apexDao.deleteByReferenceKey(DummyEntity.class, rKeySetIn);
- assertEquals(2, deletedRCount);
-
- apexDao.update(new DummyEntity(new AxReferenceKey(owner5Key, "EntityF"), 120.0));
- }
-}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
index 331e57f47..0f8f956ab 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,33 +36,27 @@ public class ApexModelFileWriterTest {
public void testModelFileWriter() throws IOException, ApexException {
ApexModelFileWriter<AxModel> modelFileWriter = new ApexModelFileWriter<>(true);
- modelFileWriter.setValidateFlag(true);
- assertTrue(modelFileWriter.isValidateFlag());
+ modelFileWriter.setValidate(true);
+ assertTrue(modelFileWriter.isValidate());
File tempFile = File.createTempFile("ApexFileWriterTest", "test");
File tempDir = tempFile.getParentFile();
File jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/ApexFileWriterTest.json");
- File xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ApexFileWriterTest.xml");
AxModel model = new DummyApexBasicModelCreator().getModel();
modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath());
jsonTempFile.delete();
- xmlTempFile.delete();
new File(tempDir.getAbsolutePath() + "/aaa").delete();
new File(tempDir.getAbsolutePath() + "/ccc").delete();
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
- xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ddd/ApexFileWriterTest.xml");
modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath());
jsonTempFile.delete();
- xmlTempFile.delete();
new File(tempDir.getAbsolutePath() + "/aaa/bbb").delete();
new File(tempDir.getAbsolutePath() + "/aaa").delete();
@@ -70,19 +64,14 @@ public class ApexModelFileWriterTest {
new File(tempDir.getAbsolutePath() + "/ccc").delete();
File dirA = new File(tempDir.getAbsolutePath() + "/aaa");
- //File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
+ // File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
dirA.createNewFile();
- //dirB.createNewFile();
+ // dirB.createNewFile();
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
- jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml");
final File jsonTempFile01 = jsonTempFile;
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class,
- jsonTempFile01.getAbsolutePath()))
- .hasMessageContaining("could not create directory");
-
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class,
- jsonTempFile01.getAbsolutePath()))
+ assertThatThrownBy(
+ () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile01.getAbsolutePath()))
.hasMessageContaining("could not create directory");
dirA.delete();
@@ -93,15 +82,10 @@ public class ApexModelFileWriterTest {
fileB.createNewFile();
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
- jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml");
File jsonTempFile02 = jsonTempFile;
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class,
- jsonTempFile02.getAbsolutePath()))
- .hasMessageContaining("error processing file");
-
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class,
- jsonTempFile02.getAbsolutePath()))
+ assertThatThrownBy(
+ () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile02.getAbsolutePath()))
.hasMessageContaining("error processing file");
fileB.delete();
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
index d75f20253..1152771ea 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,45 +34,33 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.lang.reflect.Field;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.PropertyException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.transform.stream.StreamSource;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
@RunWith(MockitoJUnitRunner.class)
public class ApexModelReaderTest {
- @Mock
- private Unmarshaller unmarshallerMock;
-
@Test
public void testModelReader() throws IOException, ApexException {
AxModel model = new DummyApexBasicModelCreator().getModel();
AxModel invalidModel = new DummyApexBasicModelCreator().getInvalidModel();
ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
- modelWriter.setValidateFlag(true);
- modelWriter.setJsonOutput(true);
+ modelWriter.setValidate(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
modelWriter.write(model, baos);
ByteArrayOutputStream baosInvalid = new ByteArrayOutputStream();
- modelWriter.setValidateFlag(false);
+ modelWriter.setValidate(false);
modelWriter.write(invalidModel, baosInvalid);
ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class, true);
- modelReader.setValidateFlag(true);
- assertTrue(modelReader.getValidateFlag());
+ modelReader.setValidate(true);
+ assertTrue(modelReader.isValidate());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
AxModel readModel = modelReader.read(bais);
@@ -81,26 +69,24 @@ public class ApexModelReaderTest {
ByteArrayInputStream baisInvalid = new ByteArrayInputStream(baosInvalid.toByteArray());
assertThatThrownBy(() -> modelReader.read(baisInvalid))
.hasMessageStartingWith("Apex concept validation failed");
- modelReader.setValidateFlag(false);
- assertFalse(modelReader.getValidateFlag());
+ modelReader.setValidate(false);
+ assertFalse(modelReader.isValidate());
ByteArrayInputStream bais2 = new ByteArrayInputStream(baos.toByteArray());
AxModel readModel2 = modelReader.read(bais2);
assertEquals(model, readModel2);
- modelWriter.setJsonOutput(false);
-
- ByteArrayOutputStream baosXml = new ByteArrayOutputStream();
- modelWriter.write(model, baosXml);
+ ByteArrayOutputStream baosJson = new ByteArrayOutputStream();
+ modelWriter.write(model, baosJson);
- ByteArrayInputStream baisXml = new ByteArrayInputStream(baosXml.toByteArray());
- AxModel readModelXml = modelReader.read(baisXml);
- assertEquals(model, readModelXml);
+ ByteArrayInputStream baisJson = new ByteArrayInputStream(baosJson.toByteArray());
+ AxModel readModelJson = modelReader.read(baisJson);
+ assertEquals(model, readModelJson);
String dummyString = "SomeDummyText";
ByteArrayInputStream baisDummy = new ByteArrayInputStream(dummyString.getBytes());
assertThatThrownBy(() -> modelReader.read(baisDummy))
- .hasMessage("format of input for Apex concept is neither JSON nor XML");
+ .hasMessageContaining("Unable to unmarshal Apex concept");
ByteArrayInputStream nullBais = null;
assertThatThrownBy(() -> modelReader.read(nullBais))
.hasMessage("concept stream may not be null");
@@ -115,42 +101,5 @@ public class ApexModelReaderTest {
assertThatThrownBy(() -> modelReader.read(br))
.hasMessage("Unable to read Apex concept ");
tempFile.delete();
- modelReader.setSchema(null);
-
- final File tempFileA = File.createTempFile("Apex", "Dummy");
- assertThatThrownBy(() -> modelReader.setSchema(tempFileA.getCanonicalPath()))
- .hasMessage("Unable to load schema");
- tempFile.delete();
- modelReader.setSchema("xml/example.xsd");
- }
-
- @Test
- public void testSetInputTypeError() throws ApexModelException,
- NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class, true);
-
- Field marshallerField = modelReader.getClass().getDeclaredField("unmarshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelReader, unmarshallerMock);
- marshallerField.setAccessible(false);
-
- assertThatThrownBy(() -> {
- Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(unmarshallerMock)
- .unmarshal((StreamSource) Mockito.anyObject(), Mockito.anyObject());
-
- modelReader.read("{Hello}");
- }).hasMessage("Unable to unmarshal Apex concept ");
- assertThatThrownBy(() -> {
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(unmarshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- modelReader.read("{Hello}");
- }).hasMessage("JAXB error setting unmarshaller for JSON input");
- assertThatThrownBy(() -> {
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(unmarshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- modelReader.read("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- }).hasMessage("JAXB error setting unmarshaller for XML input");
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
index ad897832e..c95106aa8 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,14 +41,12 @@ public class ApexModelSaverTest {
Path tempPath = Files.createTempDirectory("ApexTest");
assertNotNull(tempPath);
- ApexModelSaver<AxModel> modelSaver = new ApexModelSaver<AxModel>(AxModel.class, model,
- tempPath.toAbsolutePath().toString());
+ ApexModelSaver<AxModel> modelSaver =
+ new ApexModelSaver<AxModel>(AxModel.class, model, tempPath.toAbsolutePath().toString());
assertNotNull(modelSaver);
- modelSaver.apexModelWriteXml();
modelSaver.apexModelWriteJson();
Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.json").toPath());
- Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.xml").toPath());
Files.deleteIfExists(tempPath);
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
index 0b8d789ad..13e72d3e2 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,33 +38,26 @@ public class ApexModelStringWriterTest {
AxModel basicModel = new DummyApexBasicModelCreator().getModel();
assertNotNull(basicModel);
- AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey");
+ AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey");
AxKeyInfo floatKeyInfo = basicModel.getKeyInformation().get("FloatKIKey");
// Ensure marshalling is OK
ApexModelStringWriter<AxKeyInfo> stringWriter = new ApexModelStringWriter<AxKeyInfo>(true);
- assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class));
assertNotNull(stringWriter.writeJsonString(floatKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, true));
- assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, true));
+ assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, false));
- assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, false));
+ assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeXmlString(intKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeXmlString(floatKeyInfo, AxKeyInfo.class));
-
- assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class, true))
- .hasMessage("concept may not be null");
- assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class, false))
- .hasMessage("concept may not be null");
+ assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null");
+ assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null");
assertThatThrownBy(() -> stringWriter.writeJsonString(null, AxKeyInfo.class))
.hasMessage("error writing JSON string");
- assertThatThrownBy(() -> stringWriter.writeXmlString(null, AxKeyInfo.class))
- .hasMessage("error writing XML string");
- stringWriter.setValidateFlag(true);
- assertTrue(stringWriter.isValidateFlag());
+ stringWriter.setValidate(true);
+ assertTrue(stringWriter.isValidate());
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
index 147eb206a..063855976 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,65 +23,38 @@
package org.onap.policy.apex.model.basicmodel.handling;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.PropertyException;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
-import org.w3c.dom.Document;
@RunWith(MockitoJUnitRunner.class)
public class ApexModelWriterTest {
- @Mock
- private Marshaller marshallerMock;
-
@Test
public void testModelWriter() throws IOException, ApexException {
ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
- modelWriter.setValidateFlag(true);
- assertTrue(modelWriter.getValidateFlag());
- assertEquals(0, modelWriter.getCDataFieldSet().size());
-
- assertFalse(modelWriter.isJsonOutput());
- modelWriter.setJsonOutput(true);
- assertTrue(modelWriter.isJsonOutput());
- modelWriter.setJsonOutput(false);
- assertFalse(modelWriter.isJsonOutput());
+ modelWriter.setValidate(true);
+ assertTrue(modelWriter.isValidate());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
AxModel model = new DummyApexBasicModelCreator().getModel();
modelWriter.write(model, baos);
- modelWriter.setJsonOutput(true);
- modelWriter.write(model, baos);
- modelWriter.setJsonOutput(false);
- modelWriter.setValidateFlag(false);
+ modelWriter.setValidate(false);
modelWriter.write(model, baos);
- modelWriter.setJsonOutput(true);
- modelWriter.write(model, baos);
- modelWriter.setJsonOutput(false);
- modelWriter.setValidateFlag(true);
+ modelWriter.setValidate(true);
model.getKeyInformation().getKeyInfoMap().clear();
assertThatThrownBy(() -> modelWriter.write(model, baos))
- .hasMessageContaining("Apex concept xml (BasicModel:0.0.1) validation failed");
+ .hasMessageContaining("Apex concept (BasicModel:0.0.1) validation failed");
model.getKeyInformation().generateKeyInfo(model);
assertThatThrownBy(() -> modelWriter.write(null, baos))
@@ -91,73 +64,4 @@ public class ApexModelWriterTest {
assertThatThrownBy(() -> modelWriter.write(model, nullBaos))
.hasMessage("concept stream may not be null");
}
-
- @Test
- public void testSetOutputTypeError() throws ApexModelException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, PropertyException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
-
- Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelWriter, marshallerMock);
- marshallerField.setAccessible(false);
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(marshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- assertThatThrownBy(() -> modelWriter.setJsonOutput(true))
- .hasMessage("JAXB error setting marshaller for JSON output");
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(marshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- assertThatThrownBy(() -> modelWriter.setJsonOutput(false))
- .hasMessage("JAXB error setting marshaller for XML output");
- }
-
- @Test
- public void testOutputJsonError() throws ApexModelException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, JAXBException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
-
- Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelWriter, marshallerMock);
- marshallerField.setAccessible(false);
-
- modelWriter.setValidateFlag(false);
- modelWriter.setJsonOutput(true);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- AxModel model = new DummyApexBasicModelCreator().getModel();
- Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(marshallerMock)
- .marshal((AxModel) Mockito.anyObject(), (Writer) Mockito.anyObject());
- assertThatThrownBy(() -> modelWriter.write(model, baos)).hasMessage("Unable to marshal Apex concept to JSON");
- }
-
- @Test
- public void testOutputXmlError() throws ApexModelException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, JAXBException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
- modelWriter.setJsonOutput(false);
-
- Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelWriter, marshallerMock);
- marshallerField.setAccessible(false);
-
- modelWriter.setValidateFlag(false);
- modelWriter.setJsonOutput(false);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- AxModel model = new DummyApexBasicModelCreator().getModel();
-
- Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(marshallerMock)
- .marshal((AxModel) Mockito.anyObject(), (Document) Mockito.anyObject());
-
- assertThatThrownBy(() -> modelWriter.write(model, baos))
- .hasMessage("Unable to marshal Apex concept to XML");
- }
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java
deleted file mode 100644
index 3385830e2..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.handling;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import org.junit.After;
-import org.junit.Test;
-
-public class ApexSchemaGeneratorTest {
- private final PrintStream stdout = System.out;
-
- @After
- public void tearDown() throws Exception {
- System.setOut(stdout);
- }
-
- @Test
- public void test() throws IOException {
- final ByteArrayOutputStream baos0 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos0));
-
- final String[] args0 = {};
- ApexSchemaGenerator.main(args0);
- assertTrue(baos0.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos1));
-
- final String[] args1 = { "hello", "goodbye", "here" };
- ApexSchemaGenerator.main(args1);
- assertTrue(baos1.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos2));
-
- final String[] args2 = { "hello", "goodbye" };
- ApexSchemaGenerator.main(args2);
- assertTrue(baos2.toString().contains("error on Apex schema output"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos3 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos3));
-
- final String[] args3 = { "hello" };
- ApexSchemaGenerator.main(args3);
- assertTrue(baos3.toString().contains("could not create JAXB context, root class hello not found"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos4 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos4));
-
- final String[] args4 = { "org.onap.policy.apex.model.basicmodel.concepts.AxModel" };
- ApexSchemaGenerator.main(args4);
- assertTrue(baos4.toString().contains("targetNamespace=\"http://www.onap.org/policy/apex-pdp\""));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos5 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos5));
-
- final File tempFile = File.createTempFile("ApexSchemaGeneratorTest", "xsd");
- tempFile.deleteOnExit();
- final String[] args5 =
- { "org.onap.policy.apex.model.basicmodel.concepts.AxModel", tempFile.getCanonicalPath() };
-
- ApexSchemaGenerator.main(args5);
- assertTrue(tempFile.length() > 100);
- }
-}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
index 1c21b6c33..68f755886 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,10 +28,45 @@ import org.junit.Before;
import org.junit.Test;
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.DaoParameters;
import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
public class SupportApexBasicModelTest {
+ // As there are no real concepts in a basic model, this is as near to a valid model as we can get
+ private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
+
+ private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:OBSERVATION:description is blank\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
+ + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxModel:INVALID:key information not found for key "
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
+
TestApexModel<AxModel> testApexModel;
/**
@@ -75,57 +110,7 @@ public class SupportApexBasicModelTest {
}
@Test
- public void testModelWriteReadXml() throws Exception {
- testApexModel.testApexModelWriteReadXml();
- }
-
- @Test
public void testModelWriteReadJson() throws Exception {
testApexModel.testApexModelWriteReadJson();
}
-
- @Test
- public void testModelWriteReadJpa() throws Exception {
- final DaoParameters daoParameters = new DaoParameters();
- daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
- daoParameters.setPersistenceUnit("DaoTest");
-
- testApexModel.testApexModelWriteReadJpa(daoParameters);
- }
-
- // As there are no real concepts in a basic model, this is as near to a valid model as we can get
- private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
- + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
-
- private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
- + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
-
- private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
- + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:OBSERVATION:description is blank\n"
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
- + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
- + "********************************";
-
- private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
- + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
- + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxModel:INVALID:key information not found for key "
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
index 5fc678ac0..d55a9da29 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,6 @@ public class SupportBasicModelTest {
testApexModel.testApexModelVaidateMalstructured();
testApexModel.testApexModelWriteReadJson();
- testApexModel.testApexModelWriteReadXml();
}
@Test
@@ -102,14 +101,11 @@ public class SupportBasicModelTest {
}
@Test
- public void testModelCreator1XmlJson() throws ApexException {
+ public void testModelCreator1Json() throws ApexException {
final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
new SupportApexModelCreator1());
assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson())
.hasMessageStartingWith("error processing file");
-
- assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml())
- .hasMessageStartingWith("error processing file");
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
index 006c583ec..1783fc00f 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -156,19 +156,19 @@ public class SupportConceptGetterTest {
ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class);
ApexModelFileWriter<AxModel> modelWriter = new ApexModelFileWriter<AxModel>(true);
- modelReader.setValidateFlag(false);
- modelWriter.setValidateFlag(false);
+ modelReader.setValidate(false);
+ modelWriter.setValidate(false);
- File tempXmlFile = File.createTempFile("ApexModel", "xml");
- modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath());
+ File tempJsonFile = File.createTempFile("ApexModel", "json");
+ modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempJsonFile.getCanonicalPath());
- FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile);
- AxModel readXmlModel = modelReader.read(xmlFileInputStream);
- xmlFileInputStream.close();
- assertEquals(basicModel, readXmlModel);
- assertEquals(intKI91, readXmlModel.getKeyInformation().get("IntegerKIKey91"));
- assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey"));
- tempXmlFile.delete();
+ FileInputStream jsonFileInputStream = new FileInputStream(tempJsonFile);
+ AxModel readJsonModel = modelReader.read(jsonFileInputStream);
+ jsonFileInputStream.close();
+ assertEquals(basicModel, readJsonModel);
+ assertEquals(intKI91, readJsonModel.getKeyInformation().get("IntegerKIKey91"));
+ assertNotNull(readJsonModel.getKeyInformation().get("FloatKIKey"));
+ tempJsonFile.delete();
}
private AxModel setTestBasicModel() {
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java
deleted file mode 100644
index 12a67c803..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.xml;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-
-public class AxReferenceKeyAdapterTest {
-
- @Test
- public void test() throws Exception {
- AxReferenceKeyAdapter arka = new AxReferenceKeyAdapter();
- assertNotNull(arka);
-
- AxReferenceKey rkey = new AxReferenceKey("Name", "0.0.1", "PLN", "LN");
-
- String rkeyString = arka.marshal(rkey);
- assertEquals("LN", rkeyString);
- assertEquals(rkey.getLocalName(), arka.unmarshal(rkeyString).getLocalName());
- }
-}
diff --git a/model/basic-model/src/test/resources/META-INF/persistence.xml b/model/basic-model/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index 01a8989bb..000000000
--- a/model/basic-model/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2016-2018 Ericsson. 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.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
- <persistence-unit name="DaoTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner</class>
- <class>org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxModel</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.DummyEntity</class>
-
- <properties>
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database"/>
- <property name="eclipselink.logging.level" value="INFO" />
- </properties>
- </persistence-unit>
-</persistence>