aboutsummaryrefslogtreecommitdiffstats
path: root/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java')
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java69
1 files changed, 29 insertions, 40 deletions
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 d6ff31e50..331e57f47 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,27 +1,28 @@
/*
* ============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.handling;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -40,27 +41,26 @@ public class ApexModelFileWriterTest {
File tempFile = File.createTempFile("ApexFileWriterTest", "test");
File tempDir = tempFile.getParentFile();
- tempFile.delete();
-
+
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();
@@ -68,28 +68,22 @@ public class ApexModelFileWriterTest {
new File(tempDir.getAbsolutePath() + "/aaa").delete();
new File(tempDir.getAbsolutePath() + "/ccc/ddd").delete();
new File(tempDir.getAbsolutePath() + "/ccc").delete();
-
+
File dirA = new File(tempDir.getAbsolutePath() + "/aaa");
//File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
dirA.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");
- try {
- modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- fail("this test should throw an exception here");
- } catch (Exception e) {
- assertTrue(e.getMessage().contains("could not create directory "));
- }
-
- try {
- modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- fail("this test should throw an exception here");
- } catch (Exception e) {
- assertTrue(e.getMessage().contains("could not create directory "));
- }
+ assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class,
+ jsonTempFile01.getAbsolutePath()))
+ .hasMessageContaining("could not create directory");
dirA.delete();
@@ -97,23 +91,18 @@ public class ApexModelFileWriterTest {
File fileB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
dirA.mkdir();
fileB.createNewFile();
-
+
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml");
- try {
- modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- fail("this test should throw an exception here");
- } catch (Exception e) {
- assertTrue(e.getMessage().contains("error processing file "));
- }
-
- try {
- modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- fail("this test should throw an exception here");
- } catch (Exception e) {
- assertTrue(e.getMessage().contains("error processing file "));
- }
+ File jsonTempFile02 = jsonTempFile;
+ assertThatThrownBy(() -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class,
+ jsonTempFile02.getAbsolutePath()))
+ .hasMessageContaining("error processing file");
+
+ assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class,
+ jsonTempFile02.getAbsolutePath()))
+ .hasMessageContaining("error processing file");
fileB.delete();
dirA.delete();