Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Commit 6828166

Browse files
author
Rathna
committed
unit and integration test fixes
1 parent 791f294 commit 6828166

File tree

12 files changed

+56
-35
lines changed

12 files changed

+56
-35
lines changed

param.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"apiname": "pcftest",
33
"type":"swagger",
4-
"uri": "http://greeting-app-talkative-squirrel.apps.tokyo.cf-app.com/api/v3/swagger.json"
4+
"uri": "http://greeting-app-grumpy-llama-dx.apps.industry.cf-app.com/v3/swagger.json"
55
}
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.axway.apim.servicebroker.service;
22

33
import org.cloudfoundry.client.CloudFoundryClient;
4-
import org.cloudfoundry.client.v2.organizations.GetOrganizationRequest;
5-
import org.cloudfoundry.client.v2.spaces.GetSpaceRequest;
64
import org.cloudfoundry.client.v2.users.GetUserRequest;
75
import org.springframework.beans.factory.annotation.Autowired;
86
import org.springframework.stereotype.Service;
@@ -17,29 +15,10 @@ public CFClient(CloudFoundryClient cloudFoundryClient){
1715
this.cloudFoundryClient = cloudFoundryClient;
1816
}
1917

20-
public String getSpaceName(String spaceGuid) {
21-
22-
23-
String spaceName = cloudFoundryClient.spaces().get(GetSpaceRequest.builder().spaceId(spaceGuid)
24-
.build()).block().getEntity().getName();
25-
return spaceName;
26-
27-
}
28-
2918
public String getUserName(String userGuid) {
3019

31-
3220
String userName = cloudFoundryClient.users().get(GetUserRequest.builder().userId(userGuid).build()).block()
3321
.getEntity().getUsername();
3422
return userName;
35-
3623
}
37-
38-
public String getOrg(String orgGuid) {
39-
40-
String orgName = cloudFoundryClient.organizations().get(GetOrganizationRequest.builder()
41-
.organizationId(orgGuid).build()).block().getEntity().getName();
42-
return orgName;
43-
}
44-
4524
}

src/main/java/com/axway/apim/servicebroker/service/ServiceInstanceBindingController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import com.axway.apim.servicebroker.exception.ServiceBrokerException;
55
import com.axway.apim.servicebroker.model.CreateRouteBindingResponse;
66
import com.axway.apim.servicebroker.util.Util;
7+
import com.fasterxml.jackson.core.JsonProcessingException;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
910
import org.springframework.beans.factory.annotation.Autowired;
1011
import org.springframework.beans.factory.annotation.Value;
1112
import org.springframework.http.HttpStatus;
1213
import org.springframework.http.MediaType;
1314
import org.springframework.http.ResponseEntity;
15+
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
1416
import org.springframework.web.bind.annotation.*;
1517

1618
import java.util.Map;
@@ -96,4 +98,6 @@ ResponseEntity<String> deleteServiceInstanceBinding(
9698
}
9799
return new ResponseEntity<>("{}", HttpStatus.OK);
98100
}
101+
102+
99103
}

src/main/java/com/axway/apim/servicebroker/service/ServiceInstanceController.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ResponseEntity<CreateServiceInstanceResponse> createServiceInstance(
4949
@RequestHeader(value = "X-Broker-API-Request-Identity", required = false) String requestIdentity,
5050
@RequestHeader(value = "X-Broker-API-Version", required = false) String serviceBrokerVersion,
5151
@RequestBody Map<String, Object> request) {
52-
52+
//util.log(request, logger);
5353
String userGuid = serviceBrokerHelper.parseIdentity(originatingIdentityString);
5454
String userName = cfClient.getUserName(userGuid);
5555
logger.info("User Guid: {} User Name: {} ", userGuid, userName);
@@ -59,11 +59,9 @@ public ResponseEntity<CreateServiceInstanceResponse> createServiceInstance(
5959
logger.error("Cloud Foundry Context is not present");
6060
throw new ServiceBrokerException("Invalid Request");
6161
}
62-
String spaceGuid = (String) context.get("space_guid");
63-
String orgGuid = (String) context.get("organization_guid");
64-
logger.info("Space Guid: {} Organization Guid: {}", spaceGuid, orgGuid);
65-
String spaceName = cfClient.getSpaceName(spaceGuid);
66-
String cfOrgName = cfClient.getOrg(orgGuid);
62+
63+
String spaceName = (String) context.get("space_name");
64+
String cfOrgName = (String) context.get("organization_name");
6765
logger.info(" Space Name: {} Organization name : {}", spaceName, cfOrgName);
6866
String orgName = orgNamePrefix + DOT + cfOrgName + DOT + spaceName + DOT + serviceInstanceId;
6967
try {

src/main/java/com/axway/apim/servicebroker/util/Util.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import com.axway.apim.servicebroker.exception.AxwayException;
44
import com.axway.apim.servicebroker.exception.ServiceBrokerException;
5+
import com.fasterxml.jackson.core.JsonProcessingException;
56
import org.apache.commons.validator.routines.EmailValidator;
7+
import org.slf4j.Logger;
8+
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
69
//import org.springframework.cloud.servicebroker.exception.ServiceBrokerInvalidParametersException;
710

811
public class Util {
@@ -23,5 +26,16 @@ public String getNameFromEmail(String email) {
2326
return null;
2427
}
2528

29+
public void log(Object jsonObj, Logger logger) {
30+
31+
try {
32+
String request = Jackson2ObjectMapperBuilder.json().build().writeValueAsString(jsonObj);
33+
logger.info("Request {}", request);
34+
35+
} catch (JsonProcessingException e) {
36+
logger.error("Error processing JSON");
37+
}
38+
}
39+
2640

2741
}

src/test/java/com/axway/apim/servicebroker/service/AxwayAPIClientTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
import java.util.List;
77

8+
import org.cloudfoundry.client.CloudFoundryClient;
89
import org.junit.Test;
910
import org.junit.runner.RunWith;
1011
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.boot.test.context.SpringBootTest;
13+
import org.springframework.boot.test.mock.mockito.MockBean;
1214
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
1315
import org.springframework.test.context.TestPropertySource;
1416
import org.springframework.test.context.junit4.SpringRunner;
@@ -27,13 +29,16 @@ public class AxwayAPIClientTest {
2729
@Autowired
2830
AxwayAPIClient axwayAPIClient;
2931

32+
@MockBean
33+
private CloudFoundryClient cloudFoundryClient;
34+
3035
@Test
3136
public void testListAPIs() {
3237
String orgName = "Axway";
3338

3439
String orgId = axwayOrganzationClient.getOrganizationId(orgName);
35-
List<APIOrganizationAccess> axwayFrondendAPIs = axwayAPIClient.listAPIs(orgId);
36-
if (axwayFrondendAPIs.isEmpty()) {
40+
List<APIOrganizationAccess> axwayFrontendAPIs = axwayAPIClient.listAPIs(orgId);
41+
if (axwayFrontendAPIs.isEmpty()) {
3742
fail("API not found");
3843
}
3944
}

src/test/java/com/axway/apim/servicebroker/service/AxwayApplicationClientTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
import java.util.List;
77

8+
import org.cloudfoundry.client.CloudFoundryClient;
89
import org.junit.Test;
910
import org.junit.runner.RunWith;
1011
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.boot.test.context.SpringBootTest;
13+
import org.springframework.boot.test.mock.mockito.MockBean;
1214
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
1315
import org.springframework.test.context.TestPropertySource;
1416
import org.springframework.test.context.junit4.SpringRunner;
@@ -28,6 +30,9 @@ public class AxwayApplicationClientTest {
2830
@Autowired
2931
private AxwayOrganzationClient axwayOrganzationClient;
3032

33+
@MockBean
34+
private CloudFoundryClient cloudFoundryClient;
35+
3136
@Test
3237
public void getApplications() {
3338

src/test/java/com/axway/apim/servicebroker/service/AxwayClientIntgTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import java.util.HashMap;
77
import java.util.Map;
88

9+
import org.cloudfoundry.client.CloudFoundryClient;
910
import org.junit.Test;
1011
import org.junit.runner.RunWith;
1112
import org.springframework.beans.factory.annotation.Autowired;
1213
import org.springframework.boot.test.context.SpringBootTest;
14+
import org.springframework.boot.test.mock.mockito.MockBean;
1315
import org.springframework.test.context.junit4.SpringRunner;
1416

1517
import com.axway.apim.servicebroker.service.AxwayServiceBroker;
@@ -21,6 +23,9 @@ public class AxwayClientIntgTest {
2123
@Autowired
2224
AxwayServiceBroker axwayServiceBroker;
2325

26+
@MockBean
27+
private CloudFoundryClient cloudFoundryClient;
28+
2429

2530
private String email = "anna@axway.com";
2631
private String serviceInstanceId = "ED01F448-40C7-4A9D-93D0-51E7D4E93CA1";

src/test/java/com/axway/apim/servicebroker/service/AxwayServiceBrokerImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.axway.apim.servicebroker.exception.AxwayException;
44
import com.axway.apim.servicebroker.exception.ServiceBrokerException;
5+
import org.cloudfoundry.client.CloudFoundryClient;
56
import org.junit.Test;
67
import org.junit.runner.RunWith;
78
import org.springframework.beans.factory.annotation.Autowired;
89
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.boot.test.mock.mockito.MockBean;
911
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
1012
import org.springframework.test.context.TestPropertySource;
1113
import org.springframework.test.context.junit4.SpringRunner;
@@ -29,6 +31,9 @@ public class AxwayServiceBrokerImplTest {
2931
@Autowired
3032
private AxwayServiceBroker axwayServiceBroker;
3133

34+
@MockBean
35+
private CloudFoundryClient cloudFoundryClient;
36+
3237
@Test
3338
public void shouldImportAPI() {
3439

src/test/java/com/axway/apim/servicebroker/service/AxwayServiceInstanceBindingTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
import org.junit.Test;
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.boot.test.mock.mockito.MockBean;
13-
//import org.springframework.cloud.servicebroker.model.BindResource;
14-
//import org.springframework.cloud.servicebroker.model.CloudFoundryContext;
15-
//import org.springframework.cloud.servicebroker.model.Context;
16-
//import org.springframework.cloud.servicebroker.model.CreateServiceInstanceBindingRequest;
1713
import org.springframework.http.MediaType;
1814
import org.springframework.test.web.servlet.MockMvc;
1915
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@@ -72,7 +68,7 @@ public void shouldCreateServiceBinding() throws Exception {
7268
// service_id, plan_id, bindResource, context, parameters);
7369
//
7470
// String request = objectMapper.writeValueAsString(createServiceInstanceBindingRequest);
75-
String request = "";
71+
String request = "{\"service_id\":\"ED01F448-40C7-4A9D-93D0-51E7D4E93CA1\",\"plan_id\":\"1A6C15A6-1DE1-4870-A4F2-EA0A905F4A0F\",\"bind_resource\":{\"route\":\"greeting-app-grumpy-llama-dx.apps.industry.cf-app.com\"},\"context\":{\"platform\":\"cloudfoundry\",\"organization_guid\":\"2b397586-f831-40dd-b261-8a6239b4f999\",\"space_guid\":\"7376cb70-e5a4-4c47-af04-1edfdf72ead7\",\"organization_name\":\"axway\",\"space_name\":\"dev\"},\"parameters\":{\"apiname\":\"pcftest\",\"type\":\"swagger\",\"uri\":\"http://greeting-app-grumpy-llama-dx.apps.industry.cf-app.com/v3/swagger.json\"}}";
7672
mockMvc.perform(MockMvcRequestBuilders
7773
.put("/v2/service_instances/{instance_id}/service_bindings/{binding_id}", instance_id, binding_id)
7874
.with(httpBasic(username, password)).contentType(MediaType.APPLICATION_JSON).content(request)

0 commit comments

Comments
 (0)