Skip to content

Commit

Permalink
Merge aec73ad into e9fd033
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladay committed Sep 7, 2020
2 parents e9fd033 + aec73ad commit 0289e11
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/main/java/edu/tamu/app/service/manager/GitHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ public List<Sprint> getAdditionalActiveSprints() throws Exception {
}

@Override
public Object push(final FeatureRequest request) throws Exception {
public String push(final FeatureRequest request) throws Exception {
logger.info("Submitting feature request " + request.getTitle() + " to product with scope id " + request.getScopeId());
String repoId = String.valueOf(request.getProductId());

String scopeId = String.valueOf(request.getScopeId());
String title = request.getTitle();
String body = request.getDescription();
GHRepository repo = github.getRepositoryById(repoId);
return repo.createIssue(title).body(body).create();
GHRepository repo = github.getRepositoryById(scopeId);

return Long.toString(repo.createIssue(title).body(body).create().getId());
}

protected GitHub getGitHubInstance() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public interface RemoteProjectManagerBean extends ManagementBean {

public List<Sprint> getAdditionalActiveSprints() throws Exception;

public Object push(final FeatureRequest request) throws Exception;
public String push(final FeatureRequest request) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public Member getMember(final String id) throws ConnectionException, APIExceptio
}

@Override
public Object push(FeatureRequest featureRequest) throws V1Exception {
public String push(FeatureRequest featureRequest) throws V1Exception {
logger.info("Submitting feature request " + featureRequest.getTitle() + " to product with scope id " + featureRequest.getScopeId());
IAssetType requestType = services.getMeta().getAssetType("Request");
IAttributeDefinition nameAttributeDefinition = requestType.getAttributeDefinition("Name");
Expand All @@ -286,7 +286,7 @@ public Object push(FeatureRequest featureRequest) throws V1Exception {

services.save(request);

return request;
return request.getOid().getToken();
}

private void clearMembers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void setup() throws Exception {
when(internalRequestRepo.countByProductIsNull()).thenReturn(1L);
when(internalRequestRepo.create(any(InternalRequest.class))).thenReturn(TEST_REQUEST_BELLS);
when(internalRequestRepo.update(any(InternalRequest.class))).thenReturn(TEST_REQUEST_BELLS);
when(remoteProjectManagementBean.push(any(FeatureRequest.class))).thenReturn(TEST_FEATURE_REQUEST);
when(remoteProjectManagementBean.push(any(FeatureRequest.class))).thenReturn("1");
when(managementBeanRegistry.getService(any(String.class))).thenReturn(remoteProjectManagementBean);

doAnswer(new Answer<ApiResponse>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void testSubmitIssueRequest() {

@Test
public void testPushRequest() throws Exception {
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn(TEST_FEATURE_REQUEST);
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn(TEST_FEATURE_REQUEST.getScopeId());
when(managementBeanRegistry.getService(any(String.class))).thenReturn(remoteProjectManagementBean);
when(productRepo.findOne(any(Long.class))).thenReturn(TEST_PRODUCT1);
apiResponse = productController.pushRequest(TEST_FEATURE_REQUEST);
Expand All @@ -212,7 +212,7 @@ public void testPushRequest() throws Exception {

@Test
public void testGetAllRemoteProductsForProduct() throws Exception {
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn(TEST_FEATURE_REQUEST);
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn(TEST_FEATURE_REQUEST.getScopeId());
when(managementBeanRegistry.getService(any(String.class))).thenReturn(remoteProjectManagementBean);
when(productRepo.findOne(any(Long.class))).thenReturn(TEST_PRODUCT1);
apiResponse = productController.getAllRemoteProjectsForProduct(TEST_PRODUCT1.getId());
Expand All @@ -221,7 +221,7 @@ public void testGetAllRemoteProductsForProduct() throws Exception {

@Test
public void testGetAllRemoteProductsForProductWithInvalidId() throws Exception {
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn(TEST_FEATURE_REQUEST);
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn(TEST_FEATURE_REQUEST.getScopeId());
when(managementBeanRegistry.getService(any(String.class))).thenReturn(remoteProjectManagementBean);
apiResponse = productController.getAllRemoteProjectsForProduct(null);
assertEquals("Request with invalid Product id did not result in an error", ERROR, apiResponse.getMeta().getStatus());
Expand All @@ -240,7 +240,7 @@ public void testGetAllRemoteProductsForProductWithNoRemoteProductManager() {
@Test
public void testGetAllRemoteProjects() throws Exception {
when(remoteProjectManagerRepo.findOne(any(Long.class))).thenReturn(testRemoteProjectManagerOne);
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn(TEST_FEATURE_REQUEST);
when(remoteProjectManagementBean.push(TEST_FEATURE_REQUEST)).thenReturn("1");
when(managementBeanRegistry.getService(any(String.class))).thenReturn(remoteProjectManagementBean);
apiResponse = productController.getAllRemoteProjects(testRemoteProjectManagerOne.getId());
assertEquals("Remote Project Manager controller unable to get all remote projects", SUCCESS, apiResponse.getMeta().getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ public void testGetAdditionalActiveSprints() throws Exception {

@Test
public void testPush() throws Exception {
GHIssue issue = (GHIssue) gitHubService.push(TEST_FEATURE_REQUEST);
assertEquals("Didn't get expected issue", TEST_ISSUE1, issue);
String id = gitHubService.push(TEST_FEATURE_REQUEST);
assertNotNull(id);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void testGetRemoteProducts() throws ConnectionException, APIException, Oi
@Test
public void testGetRemoteProductByScopeId() throws ConnectionException, APIException, OidException, JsonParseException, JsonMappingException, IOException {
Oid oid = mock(Oid.class);

QueryResult result = mock(QueryResult.class);
IMetaModel metaModel = mock(IMetaModel.class);
IAssetType scopeType = mock(IAssetType.class);
Expand Down Expand Up @@ -499,6 +500,7 @@ public Member answer(InvocationOnMock invocation) {
@Test
public void testGetMember() throws JsonParseException, JsonMappingException, APIException, IOException, OidException, ConnectionException {
Oid oid = mock(Oid.class);

QueryResult result = mock(QueryResult.class);
IMetaModel metaModel = mock(IMetaModel.class);
IAssetType memberType = mock(IAssetType.class);
Expand Down Expand Up @@ -545,6 +547,7 @@ public void testGetMember() throws JsonParseException, JsonMappingException, API
@Test
public void testGetMemberWithAvatarImage() throws JsonParseException, JsonMappingException, APIException, IOException, OidException, ConnectionException {
Oid oid = mock(Oid.class);

QueryResult result = mock(QueryResult.class);
IMetaModel metaModel = mock(IMetaModel.class);
IAssetType memberType = mock(IAssetType.class);
Expand Down Expand Up @@ -591,6 +594,8 @@ public void testGetMemberWithAvatarImage() throws JsonParseException, JsonMappin
@Test
public void testPush() throws V1Exception {
Oid oid = mock(Oid.class);
Oid assetOid = mock(Oid.class);

IMetaModel metaModel = mock(IMetaModel.class);
IAssetType assetType = mock(IAssetType.class);
IAttributeDefinition attributeDefinition = mock(IAttributeDefinition.class);
Expand All @@ -599,11 +604,14 @@ public void testPush() throws V1Exception {

when(assetType.getAttributeDefinition(any(String.class))).thenReturn(attributeDefinition);
when(metaModel.getAssetType(any(String.class))).thenReturn(assetType);

when(services.getOid(any(String.class))).thenReturn(oid);
when(services.getMeta()).thenReturn(metaModel);

when(services.createNew(any(IAssetType.class), any(Oid.class))).thenReturn(mockAsset);

when(mockAsset.getOid()).thenReturn(assetOid);
when(assetOid.getToken()).thenReturn("token:assetOid");

doNothing().when(mockAsset).setAttributeValue(any(IAttributeDefinition.class), any(Object.class));

Object request = versionOneService.push(new FeatureRequest("New Feature", "I would like to turn off service through API.", 1L, "0001"));
Expand Down Expand Up @@ -912,9 +920,14 @@ private Asset[] getMockMemberAsset(Member member, boolean withImage) throws APIE
when(mockAvatarAttribute.getDefinition()).thenReturn(avatarAttributeDefinition);

Oid oid = mock(Oid.class);
Oid assetOid = mock(Oid.class);

when(oid.toString()).thenReturn(withImage ? "Image:" + member.getId() : "NULL");
when(mockAvatarAttribute.getValue()).thenReturn(oid);

when(mockAsset.getOid()).thenReturn(assetOid);
when(assetOid.getToken()).thenReturn("token:assetOid");

when(mockAsset.getAttribute(any(IAttributeDefinition.class))).thenAnswer(new Answer<Attribute>() {
@Override
public Attribute answer(InvocationOnMock invocation) {
Expand Down

0 comments on commit 0289e11

Please sign in to comment.