package org.onap.holmes.common.aai;
-import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.holmes.common.aai.config.AaiConfig;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
+import java.io.*;
import static org.onap.holmes.common.config.MicroServiceConfig.MSB_ADDR;
@Rule
public ExpectedException thrown = ExpectedException.none();
- private static JSONObject data;
+ private static JsonObject data;
private static AaiQuery4Ccvpn2 aai = AaiQuery4Ccvpn2.newInstance();
reader = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
reader.lines().forEach(l -> sb.append(l));
- data = JSONObject.parseObject(sb.toString());
+ data = JsonParser.parseString(sb.toString()).getAsJsonObject();
} catch (FileNotFoundException e) {
// Do nothing
} catch (IOException e) {
@Test
public void test_getServiceInstances_exception() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("site-resources").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("site-resources").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("499hkg9933NNN").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("499hkg9933NNN").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
PowerMock.replayAll();
PowerMock.verifyAll();
}
+ @Test
+ public void test_getServiceInstancesNull_exception() throws CorrelationException {
+ mockGetMethod();
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("site-resources1").toString());
+ EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
+
+ mockGetMethod();
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
+ EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
+
+ mockGetMethod();
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
+ EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
+
+ PowerMock.replayAll();
+
+ aai.getSiteServiceInstance("HkHubONSDEMOSZHKCustomer");
+ }
+
private void mockGetMethod() {
initCommonMock();