e7388b7e93abb02429a7142bf23bf106e7d29961
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / handling / ApexSchemaGeneratorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.basicmodel.handling;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.ByteArrayOutputStream;
26 import java.io.File;
27 import java.io.FileDescriptor;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.PrintStream;
31
32 import org.junit.Test;
33
34 public class ApexSchemaGeneratorTest {
35
36     @Test
37     public void test() throws IOException {
38         final ByteArrayOutputStream baos0 = new ByteArrayOutputStream();
39         System.setOut(new PrintStream(baos0));
40
41         final String[] args0 = {};
42         ApexSchemaGenerator.main(args0);
43         assertTrue(baos0.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"));
44         System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
45
46         final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
47         System.setOut(new PrintStream(baos1));
48
49         final String[] args1 = { "hello", "goodbye", "here" };
50         ApexSchemaGenerator.main(args1);
51         assertTrue(baos1.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"));
52         System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
53
54         final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
55         System.setOut(new PrintStream(baos2));
56
57         final String[] args2 = { "hello", "goodbye" };
58         ApexSchemaGenerator.main(args2);
59         assertTrue(baos2.toString().contains("error on Apex schema output"));
60         System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
61
62         final ByteArrayOutputStream baos3 = new ByteArrayOutputStream();
63         System.setOut(new PrintStream(baos3));
64
65         final String[] args3 = { "hello" };
66         ApexSchemaGenerator.main(args3);
67         assertTrue(baos3.toString().contains("could not create JAXB context, root class hello not found"));
68         System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
69
70         final ByteArrayOutputStream baos4 = new ByteArrayOutputStream();
71         System.setOut(new PrintStream(baos4));
72
73         final String[] args4 = { "org.onap.policy.apex.model.basicmodel.concepts.AxModel" };
74         ApexSchemaGenerator.main(args4);
75         assertTrue(baos4.toString().contains("targetNamespace=\"http://www.onap.org/policy/apex-pdp\""));
76         System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
77
78         final ByteArrayOutputStream baos5 = new ByteArrayOutputStream();
79         System.setOut(new PrintStream(baos5));
80
81         final File tempFile = File.createTempFile("ApexSchemaGeneratorTest", "xsd");
82         final String[] args5 =
83             { "org.onap.policy.apex.model.basicmodel.concepts.AxModel", tempFile.getCanonicalPath() };
84
85         ApexSchemaGenerator.main(args5);
86         assertTrue(tempFile.length() > 100);
87         System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
88         tempFile.delete();
89     }
90 }