* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Wipro Limited.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.lenient;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.CloudRegion;
+import org.onap.aai.domain.yang.Tenant;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.so.SoRequestStatus;
import org.onap.policy.so.SoResponse;
+@RunWith(MockitoJUnitRunner.class)
public class SoOperationTest extends BasicSoOperation {
private static final List<String> PROP_NAMES = Collections.emptyList();
assertTrue(oper.isSuccess(rawResponse, response));
- when(rawResponse.getStatus()).thenReturn(500);
+ lenient().when(rawResponse.getStatus()).thenReturn(500);
assertTrue(oper.isSuccess(rawResponse, response));
}
@Test
public void testSetOutcome() {
// success case
- when(rawResponse.getStatus()).thenReturn(200);
+ lenient().when(rawResponse.getStatus()).thenReturn(200);
assertSame(outcome, oper.setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response));
assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertSame(response, outcome.getResponse());
// failure case
- when(rawResponse.getStatus()).thenReturn(500);
+ lenient().when(rawResponse.getStatus()).thenReturn(500);
assertSame(outcome, oper.setOutcome(outcome, OperationResult.FAILURE, rawResponse, response));
assertEquals(OperationResult.FAILURE, outcome.getResult());
assertTrue(oper.buildConfigurationParameters().isEmpty());
}
+ @Test
+ public void testConstructCloudConfiguration() throws Exception {
+ Tenant tenantItem = new Tenant();
+ tenantItem.setTenantId("my-tenant-id");
+
+ CloudRegion cloudRegionItem = new CloudRegion();
+ cloudRegionItem.setCloudRegionId("my-cloud-id");
+
+ assertThatCode(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem)).doesNotThrowAnyException();
+
+ tenantItem.setTenantId(null);
+ assertThatIllegalArgumentException()
+ .isThrownBy(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem))
+ .withMessageContaining("missing tenant ID");
+ tenantItem.setTenantId("my-tenant-id");
+
+ cloudRegionItem.setCloudRegionId(null);
+ assertThatIllegalArgumentException()
+ .isThrownBy(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem))
+ .withMessageContaining("missing cloud region ID");
+ cloudRegionItem.setCloudRegionId("my-cloud-id");
+ }
+
+ @Test
+ public void testGetRequiredText() throws Exception {
+
+ assertThatCode(() -> oper.getRequiredText("some value", "my value")).doesNotThrowAnyException();
+
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getRequiredText("some value", null))
+ .withMessageContaining("missing some value");
+ }
+
@Test
public void testGetCoder() throws CoderException {
Coder opcoder = oper.getCoder();