2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017 Amdocs
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 package org.onap.aai.sparky.dal.elasticsearch;
\r
25 import java.util.HashMap;
\r
26 import java.util.Map;
\r
28 import org.junit.Assert;
\r
29 import org.junit.Test;
\r
30 import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
\r
31 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
\r
32 import org.onap.aai.sparky.dal.NetworkTransaction;
\r
33 import org.onap.aai.sparky.dal.rest.HttpMethod;
\r
34 import org.onap.aai.sparky.dal.rest.OperationResult;
\r
36 public class ElasticSearchEntityStatisticsTest {
\r
39 public void testInitializeCountersFromOxmEntityDescriptors_NotNullDescriptors() {
\r
41 ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader());
\r
42 Map<String, OxmEntityDescriptor> descriptors = new HashMap<>();
\r
44 OxmEntityDescriptor oxmEd = new OxmEntityDescriptor();
\r
45 oxmEd.setEntityName("entity-1");
\r
46 oxmEd.setGeoLatName("geoLatName-1");
\r
48 descriptors.put("entity-1", oxmEd);
\r
50 eses.initializeCountersFromOxmEntityDescriptors(descriptors);
\r
55 public void testInitializeCountersFromOxmEntityDescriptors_NullDescriptors() {
\r
57 ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader());
\r
58 Map<String, OxmEntityDescriptor> descriptors = null;
\r
59 eses.initializeCountersFromOxmEntityDescriptors(descriptors);
\r
63 public void testUpdateCounters() {
\r
65 ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader());
\r
66 Map<String, OxmEntityDescriptor> descriptors = new HashMap<>();
\r
68 OxmEntityDescriptor oxmEd = new OxmEntityDescriptor();
\r
69 oxmEd.setEntityName("entity-1");
\r
70 oxmEd.setGeoLatName("geoLatName-1");
\r
71 descriptors.put("entity-1", oxmEd);
\r
73 eses.initializeCountersFromOxmEntityDescriptors(descriptors);
\r
75 OperationResult result = new OperationResult();
\r
76 result.setResultCode(200);
\r
77 result.setResult("result-1");
\r
78 result.setNumRequestRetries(1);
\r
79 NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
\r
80 eses.updateCounters(ntwTxn);
\r
82 result.setResultCode(201);
\r
83 NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
\r
84 eses.updateCounters(ntwTxn1);
\r
86 result.setResultCode(202);
\r
87 NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
\r
88 eses.updateCounters(ntwTxn2);
\r
89 NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
\r
90 eses.updateCounters(ntwTxn3);
\r
92 result.setResultCode(101);
\r
93 NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
\r
94 eses.updateCounters(ntwTxn4);
\r
95 NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
\r
96 eses.updateCounters(ntwTxn5);
\r
98 String statistics = eses.getStatisticsReport();
\r
99 Assert.assertNotNull(statistics);
\r