2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.rest.ueb;
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;
37 import javax.ws.rs.core.Response;
38 import java.io.UnsupportedEncodingException;
40 import java.net.URISyntaxException;
41 import java.util.HashMap;
42 import java.util.UUID;
44 import static org.junit.Assert.assertEquals;
46 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
47 public class UEBNotificationTest extends AAISetup {
49 public static final String BASE_PATH = "/aai";
51 protected EdgeSerializer edgeSer;
53 protected EdgeIngestor ei;
55 private SchemaVersion version;
56 private final ModelType introspectorFactoryType = ModelType.MOXY;
57 private Loader loader;
59 public QueryStyle queryStyle = QueryStyle.TRAVERSAL_URI;
63 public void setup() throws Exception {
64 version = schemaVersions.getDefaultVersion();
65 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
69 public void verifyUriNoIssues() throws AAIException, URISyntaxException, UnsupportedEncodingException {
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(),
78 Response.Status.CREATED,
84 assertEquals("One event created", 1, uebNotification.getEvents().size());
87 BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
88 uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());
92 public void verifyUriWithBaseAndUri() throws AAIException, URISyntaxException, UnsupportedEncodingException {
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(),
101 Response.Status.CREATED,
104 new HashMap<>(), BASE_PATH);
106 assertEquals("One event created", 1, uebNotification.getEvents().size());
109 BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
110 uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());