Enhancements for the aai-common library
[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 org.junit.Before;
24 import org.junit.Test;
25 import org.onap.aai.AAISetup;
26 import org.onap.aai.edges.EdgeIngestor;
27 import org.onap.aai.exceptions.AAIException;
28 import org.onap.aai.introspection.Introspector;
29 import org.onap.aai.introspection.Loader;
30 import org.onap.aai.introspection.ModelType;
31 import org.onap.aai.serialization.db.EdgeSerializer;
32 import org.onap.aai.serialization.engines.QueryStyle;
33 import org.onap.aai.setup.SchemaVersion;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.test.annotation.DirtiesContext;
36
37 import javax.ws.rs.core.Response;
38 import java.io.UnsupportedEncodingException;
39 import java.net.URI;
40 import java.net.URISyntaxException;
41 import java.util.HashMap;
42 import java.util.UUID;
43
44 import static org.junit.Assert.assertEquals;
45
46 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
47 public class UEBNotificationTest extends AAISetup {
48
49     public static final String BASE_PATH = "/aai";
50     @Autowired
51     protected EdgeSerializer edgeSer;
52     @Autowired
53     protected EdgeIngestor ei;
54
55     private SchemaVersion version;
56     private final ModelType introspectorFactoryType = ModelType.MOXY;
57     private Loader loader;
58
59     public QueryStyle queryStyle = QueryStyle.TRAVERSAL_URI;
60
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(
76             UUID.randomUUID().toString(),
77             "JUNIT-SOT",
78             Response.Status.CREATED,
79             uri,
80             pserver,
81             new HashMap<>(),
82             BASE_PATH);
83
84         assertEquals("One event created", 1, uebNotification.getEvents().size());
85         assertEquals(
86             "Uri is correct",
87             BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
88             uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());
89     }
90
91     @Test
92     public void verifyUriWithBaseAndUri() throws AAIException, URISyntaxException, UnsupportedEncodingException {
93
94         Introspector pserver = loader.introspectorFromName("pserver");
95         pserver.setValue("hostname", "hn");
96         URI uri = new URI(BASE_PATH + "/v12/cloud-infrastructure/pservers/pserver/hn");
97         UEBNotification uebNotification = new UEBNotification(loader, loaderFactory, schemaVersions);
98         uebNotification.createNotificationEvent(
99             UUID.randomUUID().toString(),
100             "JUNIT-SOT",
101             Response.Status.CREATED,
102             uri,
103             pserver,
104             new HashMap<>(), BASE_PATH);
105
106         assertEquals("One event created", 1, uebNotification.getEvents().size());
107         assertEquals(
108             "Uri is correct",
109             BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
110             uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());
111     }
112 }