2 * ============LICENSE_START=======================================================
3 * SPARKY (AAI UI service)
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.onap.aai.sparky.synchronizer;
28 import java.io.IOException;
29 import java.security.NoSuchAlgorithmException;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mockito;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
37 import org.onap.aai.sparky.util.LogValidator;
39 import ch.qos.logback.classic.Level;
43 * The Class IndexDocumentTest.
45 @RunWith(MockitoJUnitRunner.class)
46 public class IndexDocumentTest {
48 private LogValidator logValidator;
49 private OxmModelLoader oxmModelLoader;
54 * @throws Exception the exception
57 public void init() throws Exception {
58 logValidator = new LogValidator();
59 logValidator.initializeLogger(Level.WARN);
60 oxmModelLoader = Mockito.mock(OxmModelLoader.class);
64 * Validate basic construction.
66 * @throws NoSuchAlgorithmException the no such algorithm exception
67 * @throws IOException Signals that an I/O exception has occurred.
70 public void validateBasicConstruction() throws NoSuchAlgorithmException, IOException {
73 * String testDate = "2016-12-21 00:00:00.00"; OxmEntityDescriptor d = new
74 * OxmEntityDescriptor(); d.setEntityName("service-instance");
75 * d.setPrimaryKeyAttributeName(Arrays.asList("service-instance-id"));
76 * d.setSearchableAttributes(Arrays.asList("service-instance-id"));
78 * Mockito.when(oxmModelLoader.getEntityDescriptor(anyString())).thenReturn(d);
80 * SearchableEntity id1 = new SearchableEntity(oxmModelLoader);
82 * id1.setEntityType("service-instance"); id1.setEntityPrimaryKeyValue("DUP2");
83 * id1.addSearchTagWithIdx("DUP2", String.valueOf(1));
85 * id1.deriveFields(); id1.setEntityTimeStamp(testDate); ObjectMapper mapper = new
88 * String objStr = id1.getIndexDocumentJson();
90 * JsonNode indexDocNode = mapper.readTree(objStr);
94 * ObjectNode expectedNode = mapper.createObjectNode(); expectedNode.put("entityType",
95 * "service-instance"); expectedNode.put("entityPrimaryKeyValue", "DUP2");
96 * expectedNode.put("searchTagIDs", "1"); expectedNode.put("searchTags", "DUP2");
97 * expectedNode.put("crossEntityReferenceValues", ""); expectedNode.put("lastmodTimestamp",
100 * assertTrue(NodeUtils.isEqual(expectedNode, indexDocNode)); // Test if the timestamp is
101 * calculated when the node is being created
102 * assertTrue(NodeUtils.getNodeFieldAsText(indexDocNode, "lastmodTimestamp") != null);