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.editattributes;
28 import static org.junit.Assert.assertEquals;
30 import java.util.HashMap;
33 import javax.ws.rs.core.Response.Status;
35 import org.eclipse.persistence.dynamic.DynamicType;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39 import org.onap.aai.restclient.client.OperationResult;
40 import org.onap.aai.setup.Version;
41 import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
42 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
43 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
44 import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
45 import org.onap.aai.sparky.editattributes.AttributeUpdater.AaiEditObject;
50 * The Class AttributeUpdaterTest.
52 public class AttributeUpdaterTest {
54 private ActiveInventoryAdapter aaiAdapter;
59 * @throws Exception the exception
62 public void setUp() throws Exception {
64 aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
72 public void testUpdateObjectAttribute() throws Exception {
74 OxmEntityDescriptor desc = new OxmEntityDescriptor();
75 desc.addPrimaryKeyName("hostname");
76 desc.setEntityName("pserver");
77 Version version = Version.V11;
78 OxmEntityLookup entityLookup = new OxmEntityLookup();
79 entityLookup.addEntityDescriptor("pserver", desc);
81 AttributeUpdater updater =
82 new AttributeUpdater(new OxmModelLoader(version, null, null), entityLookup, aaiAdapter);
83 Map<String, Object> attributes = new HashMap<>();
84 attributes.put("prov-status", "PREPROV");
85 attributes.put("in-maint", "true");
86 OperationResult result = updater.updateObjectAttribute(
87 "cloud-infrastructure/pservers/pserver/something", attributes, "someid");
88 assertEquals(Status.FORBIDDEN.getStatusCode(), result.getResultCode());
92 // This needs the OXM file in place to work.
94 * Test get edit object from uri.
96 * @throws Exception the exception
98 @Test(expected = NullPointerException.class)
99 public void testGetEditObjectFromUri() throws Exception {
100 Version version = Version.V11;
101 OxmModelLoader loader = new OxmModelLoader(version, null, null);
104 OxmEntityDescriptor desc = new OxmEntityDescriptor();
105 desc.addPrimaryKeyName("hostname");
106 desc.setEntityName("pserver");
108 OxmEntityLookup entityLookup = new OxmEntityLookup();
109 entityLookup.addEntityDescriptor("pserver", desc);
112 // DynamicType mockType = Mockito.mock(DynamicType.class);
113 // Class<? extends DynamicEntity> mockDynamicEntity = Mockito.mock(DynamicEntity.class);
115 // Mockito.when(mockType.getJavaClass()).thenReturn(mockDynamicEntity);
119 HashMap<String, DynamicType> typeLookup = new HashMap<String, DynamicType>();
120 // typeLookup.put("pserver", mockType);
122 entityLookup.setEntityTypeLookup(typeLookup);
125 AttributeUpdater updater =
126 new AttributeUpdater(new OxmModelLoader(version, null, null), entityLookup, aaiAdapter);
127 AaiEditObject result = updater.getEditObjectFromUri(null);
128 assertEquals("Pserver", result.getObjectType());
129 assertEquals("pserver", result.getRootElement());
130 assertEquals("hostname", result.getKeyName());
131 assertEquals("mtznjtax101", result.getKeyValue());
135 * Test get relative uri.
137 * @throws Exception the exception
141 public void testGetRelativeUri() throws Exception {
143 OxmEntityDescriptor desc = new OxmEntityDescriptor();
144 desc.addPrimaryKeyName("hostname");
145 desc.setEntityName("pserver");
147 OxmEntityLookup entityLookup = new OxmEntityLookup();
148 entityLookup.addEntityDescriptor("pserver", desc);
150 AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(null,null), entityLookup, aaiAdapter);
151 // Test entity uri without "/aai/version/"
152 String result = updater.getRelativeUri("cloud-infrastructure/pservers/pserver/mtznjtax101");
153 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
154 result = updater.getRelativeUri("/aai/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
155 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
157 result = updater.getRelativeUri("/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
158 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
160 result = updater.getRelativeUri("aai/v88/cloud-infrastructure/pservers/pserver/mtznjtax101");
161 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
163 result = updater.getRelativeUri("/cloud-infrastructure/pservers/pserver/mtznjtax101");
164 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);