Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / ueb / UEBNotificationTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aai.rest.ueb;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.io.UnsupportedEncodingException;
26 import java.net.URI;
27 import java.net.URISyntaxException;
28 import java.util.HashMap;
29 import java.util.UUID;
30
31 import javax.ws.rs.core.Response;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aai.AAISetup;
36 import org.onap.aai.edges.EdgeIngestor;
37 import org.onap.aai.exceptions.AAIException;
38 import org.onap.aai.introspection.Introspector;
39 import org.onap.aai.introspection.Loader;
40 import org.onap.aai.introspection.ModelType;
41 import org.onap.aai.serialization.db.EdgeSerializer;
42 import org.onap.aai.serialization.engines.QueryStyle;
43 import org.onap.aai.setup.SchemaVersion;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.test.annotation.DirtiesContext;
46
47 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
48 public class UEBNotificationTest extends AAISetup {
49
50     public static final String BASE_PATH = "/aai";
51     @Autowired
52     protected EdgeSerializer edgeSer;
53     @Autowired
54     protected EdgeIngestor ei;
55
56     private SchemaVersion version;
57     private final ModelType introspectorFactoryType = ModelType.MOXY;
58     private Loader loader;
59
60     public QueryStyle queryStyle = QueryStyle.TRAVERSAL_URI;
61
62     @Before
63     public void setup() throws Exception {
64         version = schemaVersions.getDefaultVersion();
65         loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
66     }
67
68     @Test
69     public void verifyUriNoIssues() throws AAIException, URISyntaxException, UnsupportedEncodingException {
70
71         Introspector pserver = loader.introspectorFromName("pserver");
72         pserver.setValue("hostname", "hn");
73         URI uri = new URI("/cloud-infrastructure/pservers/pserver/hn");
74         UEBNotification uebNotification = new UEBNotification(loader, loaderFactory, schemaVersions);
75         uebNotification.createNotificationEvent(UUID.randomUUID().toString(), "JUNIT-SOT", Response.Status.CREATED, uri,
76                 pserver, new HashMap<>(), BASE_PATH);
77
78         assertEquals("One event created", 1, uebNotification.getEvents().size());
79         assertEquals("Uri is correct",
80                 BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
81                 uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());
82     }
83
84     @Test
85     public void verifyUriWithBaseAndUri() throws AAIException, URISyntaxException, UnsupportedEncodingException {
86
87         Introspector pserver = loader.introspectorFromName("pserver");
88         pserver.setValue("hostname", "hn");
89         URI uri = new URI(BASE_PATH + "/v12/cloud-infrastructure/pservers/pserver/hn");
90         UEBNotification uebNotification = new UEBNotification(loader, loaderFactory, schemaVersions);
91         uebNotification.createNotificationEvent(UUID.randomUUID().toString(), "JUNIT-SOT", Response.Status.CREATED, uri,
92                 pserver, new HashMap<>(), BASE_PATH);
93
94         assertEquals("One event created", 1, uebNotification.getEvents().size());
95         assertEquals("Uri is correct",
96                 BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
97                 uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());
98     }
99 }