c7ab1d9a00748265801cc292e912985f10ec3b86
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.testsuites.integration.common.model;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.nio.file.Files;
31 import java.nio.file.Path;
32 import java.util.Comparator;
33 import org.junit.Test;
34 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
35
36 /**
37  * Test the sample domain model saver.
38  */
39 public class SampleDomainModelSaverTest {
40
41     @Test
42     public void testSampleDomainModelSaver() throws IOException, ApexException {
43         assertThatThrownBy(() -> SampleDomainModelSaver.main(null)).isInstanceOf(NullPointerException.class);
44
45         String[] args0 =
46             { "two", "arguments" };
47
48         SampleDomainModelSaver.main(args0);
49
50         Path tempDirectory = Files.createTempDirectory("ApexModelTempDir");
51         String[] args1 =
52             { tempDirectory.toString() };
53
54         SampleDomainModelSaver.main(args1);
55
56         File tempDir = new File(tempDirectory.toString());
57         assertTrue(tempDir.isDirectory());
58         assertEquals(10, tempDir.listFiles().length);
59
60         Files.walk(tempDirectory).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
61     }
62 }