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/DummyEntity.java6
-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.java5
-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
11 files changed, 56 insertions, 380 deletions
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 cd8b52ce6..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
@@ -23,17 +23,11 @@ package org.onap.policy.apex.model.basicmodel.concepts;
import java.util.Arrays;
import java.util.List;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
public class DummyEntity extends AxConcept {
private static final long serialVersionUID = -2962570563281067894L;
- @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/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 bb9776fc7..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
@@ -110,11 +110,6 @@ public class SupportApexBasicModelTest {
}
@Test
- public void testModelWriteReadXml() throws Exception {
- testApexModel.testApexModelWriteReadXml();
- }
-
- @Test
public void testModelWriteReadJson() throws Exception {
testApexModel.testApexModelWriteReadJson();
}
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());
- }
-}