- public void testGetServiceInstance() {
- // @formatter:off
- verifyItems(OperationProperties.AAI_SERVICE, ServiceInstance::new,
- (cq, instance) -> when(cq.getServiceInstance()).thenReturn(instance),
- () -> oper.getServiceInstance(),
- "missing VNF Service Item");
- // @formatter:on
- }
-
- @Test
- public void testGetDefaultTenant() {
- // @formatter:off
- verifyItems(OperationProperties.AAI_DEFAULT_TENANT, Tenant::new,
- (cq, tenant) -> when(cq.getDefaultTenant()).thenReturn(tenant),
- () -> oper.getDefaultTenant(),
- "missing Default Tenant Item");
- // @formatter:on
- }
-
- @Test
- public void testGetVnfModel() {
- GenericVnf vnf = new GenericVnf();
- vnf.setModelVersionId(VERSION_ID);
-
- // @formatter:off
- verifyItems(OperationProperties.AAI_VNF_MODEL, ModelVer::new,
- (cq, model) -> when(cq.getModelVerByVersionId(VERSION_ID)).thenReturn(model),
- () -> oper.getVnfModel(vnf),
- "missing generic VNF Model");
- // @formatter:on
- }
-
- @Test
- public void testGetServiceModel() {
- ServiceInstance service = new ServiceInstance();
- service.setModelVersionId(VERSION_ID);
-
- // @formatter:off
- verifyItems(OperationProperties.AAI_SERVICE_MODEL, ModelVer::new,
- (cq, model) -> when(cq.getModelVerByVersionId(VERSION_ID)).thenReturn(model),
- () -> oper.getServiceModel(service),
- "missing Service Model");
- // @formatter:on
- }
-
- @Test
- public void testGetDefaultCloudRegion() {
- // @formatter:off
- verifyItems(OperationProperties.AAI_DEFAULT_CLOUD_REGION, CloudRegion::new,
- (cq, region) -> when(cq.getDefaultCloudRegion()).thenReturn(region),
- () -> oper.getDefaultCloudRegion(),
- "missing Default Cloud Region");
- // @formatter:on
- }
-
- private <T> void verifyItems(String propName, Supplier<T> maker, BiConsumer<AaiCqResponse, T> setter,
- Supplier<T> getter, String errmsg) {
-
- AaiCqResponse cq = mock(AaiCqResponse.class);
- params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq);
-
- // in neither property nor custom query
- assertThatIllegalArgumentException().isThrownBy(getter::get).withMessage(errmsg);
-
- // only in custom query
- final T item1 = maker.get();
- setter.accept(cq, item1);
- assertSame(item1, getter.get());