Merge "Reformat sdnr devicemanager-onf to ONAP code style"
[ccsdk/features.git] / sdnr / wt / common / src / test / java / org / onap / ccsdk / features / sdnr / wt / common / test / TestPomfile.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.common.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.fail;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import javax.xml.parsers.ParserConfigurationException;
32
33 import org.junit.Test;
34 import org.onap.ccsdk.features.sdnr.wt.common.file.PomFile;
35 import org.onap.ccsdk.features.sdnr.wt.common.file.PomPropertiesFile;
36 import org.xml.sax.SAXException;
37
38 public class TestPomfile {
39
40     private static final String TESTPROPERTY_KEY = "elasticsearch-rest-client.version";
41     private static final String TESTPROPERTY_VALUE = "6.4.3";
42     private static final String POMFILENAME = "pom.xml";
43     private static final String POM_PROPERTY = "#Generated by org.apache.felix.bundleplugin\n"
44             + "#Tue Nov 19 11:20:33 CET 2019\n" + "version=0.7.0-SNAPSHOT\n"
45             + "groupId=org.onap.ccsdk.features.sdnr.wt\n" + "artifactId=sdnr-wt-data-provider-provider\n";
46     //private static final Date DATE_EXPECTED = new Date(119, 10, 19, 11, 20, 33);
47
48     @Test
49     public void test() {
50         PomFile pom = null;
51         try {
52             pom = new PomFile(new FileInputStream(POMFILENAME));
53         } catch (ParserConfigurationException | SAXException | IOException e) {
54             fail(e.getMessage());
55         }
56         assertNotNull(pom);
57         assertEquals(TESTPROPERTY_VALUE, pom.getProperty(TESTPROPERTY_KEY));
58
59     }
60
61     @Test
62     public void testProp() {
63         PomPropertiesFile file = null;
64         try {
65             file = new PomPropertiesFile(new ByteArrayInputStream(POM_PROPERTY.getBytes()));
66         } catch (IOException e) {
67             // TODO Auto-generated catch block
68             e.printStackTrace();
69         }
70         assertNotNull(file);
71         assertNotNull(file.getBuildDate());
72     }
73 }