summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShiwei Tian <tian.shiwei@zte.com.cn>2017-09-27 17:03:16 +0800
committerShiwei Tian <tian.shiwei@zte.com.cn>2017-09-27 17:03:16 +0800
commit43e1dfbcdb2a84d5e69a8b038f76fa626718e5d7 (patch)
tree245744d43d620b89dcc14cd5db0746357bf013b7
parentc9ed775685b01f5622618216748eeac3000285c4 (diff)
modify unit test and aai bug
Issue-ID: HOLMES-44 Change-Id: I83b7d90eb25289326a76613ea160442ed3bdd1e1 Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java4
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/HttpsUtilsTest.java95
2 files changed, 97 insertions, 2 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
index aa840ba..074c509 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
@@ -76,7 +76,7 @@ public class AaiQuery {
private String getResourceLinksResponse(String vserverId, String vserverName) throws CorrelationException {
String url = getBaseUrl(getMsbSuffixAddr(AaiConfig.AAI_VNF_ADDR) + "vserver-id:EQUALS:" + vserverId);
String response = getResponse(url);
- if (response.equals("")) {
+ if ("".equals(response) || "{}".equals(response)) {
url = getBaseUrl(AaiConfig.AAI_VM_ADDR + "vserver-name:EQUALS:" + vserverName);
response = getResponse(url);
}
@@ -86,7 +86,7 @@ public class AaiQuery {
private String getVnfDataResponse(String vnfId, String vnfName) throws CorrelationException {
String url = getBaseUrl(getMsbSuffixAddr(AaiConfig.AAI_VM_ADDR)+ "vnf-id=" + vnfId);
String response = getResponse(url);
- if (response.equals("")) {
+ if ("".equals(response) || "{}".equals(response)) {
url = getBaseUrl(AaiConfig.AAI_VNF_ADDR + "vnf-name=" + vnfName);
response = getResponse(url);
}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/HttpsUtilsTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/HttpsUtilsTest.java
new file mode 100644
index 0000000..bbd9a0c
--- /dev/null
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/HttpsUtilsTest.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.common.utils;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+@PrepareForTest({HttpsUtils.class, CloseableHttpClient.class})
+@RunWith(PowerMockRunner.class)
+public class HttpsUtilsTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ private HttpsUtils httpsUtils;
+
+ @Before
+ public void setUp() {
+ httpsUtils = new HttpsUtils();
+ }
+
+
+ @Test
+ public void testHttpsUtil_get_excepiton() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to use get method query data from server");
+ String url = "host";
+ Map<String, String> header = new HashMap<>();
+ header.put("accept", "application/json");
+ Map<String, String> para = new HashMap<>();
+ para.put("tset", "1111");
+ String response = HttpsUtils.get(url, header);
+ assertThat(response, equalTo(""));
+ }
+
+ @Test
+ public void testHttpsUtil_post_excepiton() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to use post method query data from server");
+ String url = "host";
+ Map<String, String> header = new HashMap<>();
+ header.put("accept", "application/json");
+ Map<String, String> para = new HashMap<>();
+ para.put("tset", "1111");
+ String response = HttpsUtils.post(url, header, para, null);
+ assertThat(response, equalTo(""));
+ }
+
+ @Test
+ public void testHttpsUtil_getResponseEntity_input_null() throws Exception {
+ PowerMock.resetAll();
+ httpsUtils = PowerMock.createMock(HttpsUtils.class);
+ PowerMock.replayAll();
+ String actual = Whitebox.invokeMethod(httpsUtils, "getResponseEntity", null);
+ PowerMock.verifyAll();
+ assertThat(actual, equalTo(""));
+ }
+
+
+ @Test
+ public void testHttpsUtil_getHttpClient_exception() throws Exception {
+ PowerMock.resetAll();
+ thrown.expect(Exception.class);
+ Whitebox.invokeMethod(HttpsUtils.class, "getHttpClient");
+ PowerMock.verifyAll();
+ }
+
+} \ No newline at end of file
id='n329' href='#n329'>329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575