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 static org.junit.Assert.assertEquals;
25 import java.io.UnsupportedEncodingException;
27 import java.net.URISyntaxException;
28 import java.util.HashMap;
29 import java.util.UUID;
31 import javax.ws.rs.core.Response;
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;
47 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
48 public class UEBNotificationTest extends AAISetup {
50 public static final String BASE_PATH = "/aai";
52 protected EdgeSerializer edgeSer;
54 protected EdgeIngestor ei;
56 private SchemaVersion version;
57 private final ModelType introspectorFactoryType = ModelType.MOXY;
58 private Loader loader;
60 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(UUID.randomUUID().toString(), "JUNIT-SOT", Response.Status.CREATED, uri,
76 pserver, new HashMap<>(), BASE_PATH);
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());
85 public void verifyUriWithBaseAndUri() throws AAIException, URISyntaxException, UnsupportedEncodingException {
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);
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());