Skip to content

Commit

Permalink
Changes have done as per review comments.
Browse files Browse the repository at this point in the history
Change1:Reframed the Error Message.
Change2:Renamed the test methods.
Change3:Added the TODO comments for future references.
  • Loading branch information
balmukundblr committed Jan 12, 2018
1 parent d514a8d commit 14d1494
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void validateDAReferenceToSfcAndSecurityGroup(EntityManager em, Distribu
try {
validateVSReferenceToSfcAndSecurityGroup(em, vs);
} catch (VmidcBrokerValidationException ex) {
throw new VmidcBrokerValidationException(da.getName() + " " + ex.getMessage());
throw new VmidcBrokerValidationException(String.format("Cannot delete the distributed appliance '%s' reason:",da.getName())+" "+ex.getMessage());
}
}
}
Expand All @@ -94,12 +94,10 @@ private void validateSfcReferenceToSecurityGroup(EntityManager em, ServiceFuncti
String sgNames = sgList.stream().filter(sg -> !sg.getMarkedForDeletion()).map(sg -> sg.getName())
.collect(Collectors.joining(", "));
if (!sgNames.isEmpty()) {
throw new VmidcBrokerValidationException(String.format(
"distributed appliance cannot be deleted which is currently referencing Service Function Chain '%s' and binded to a SecurityGroup(s) '%s'",
throw new VmidcBrokerValidationException(String.format("Service Function Chain '%s' and binded to a Security Group(s) '%s'",
sfc.getName(), sgNames));
} else if (!sfc.getMarkedForDeletion() && sfc != null) {
throw new VmidcBrokerValidationException(String.format(
"distributed appliance cannot be deleted which is currently referencing Service Function Chain '%s'",
throw new VmidcBrokerValidationException(String.format("Service Function Chain '%s'",
sfc.getName()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

//TODO balmukund: Because the class under test now has a dependency on a complex DB query listReferencedVSBySecurityGroup it must be refactored to use an in mem db.
// Until then powermock is being used to mock static dependencies. This should be removed when this refactoring happens.
@RunWith(PowerMockRunner.class)
@PrepareForTest({SecurityGroupEntityMgr.class,DistributedApplianceEntityMgr.class})
public class DeleteDistributedApplianceRequestValidatorTest {
Expand Down Expand Up @@ -137,8 +138,10 @@ public void testValidateAndLoad_WithNonForceDeleteRequestAndMarkedForDeletionDA_
Assert.assertEquals("The received ID in non force delete case is different than expected VALID_ID_FOR_DELETION.", VALID_ID_FOR_DELETION, da.getId());
}

//TODO balmukund: Because the class under test now has a dependency on a complex DB query listReferencedVSBySecurityGroup it must be refactored to use an in mem db.
// until then Powermock is being used to mock static dependencies. This should be removed when this refactoring happens.
@Test
public void testValidateAndLoad_WhenChainedToSfcDeleteRequest_ThrowsValidationException() throws Exception {
public void testValidateAndLoad_WhenChainedToSfc_ThrowsValidationException() throws Exception {
// Arrange
final Long VALID_ID_WITH_SFC = 4l;
DistributedAppliance da = createDA(VALID_ID_WITH_SFC, false);
Expand All @@ -163,7 +166,7 @@ public void testValidateAndLoad_WhenChainedToSfcDeleteRequest_ThrowsValidationEx
}

@Test
public void testValidateDAReferenceToSfcAndSecurityGroup_WhenChainedToSfcAndSgDeleteRequest_ThrowsValidationException()
public void testValidateAndLoad_WhenChainedToSfcAndSg_WhenSfcMode_ThrowsValidationException()
throws Exception {
// Arrange
final Long VALID_ID_WITH_SFC = 4l;
Expand All @@ -185,17 +188,15 @@ public void testValidateDAReferenceToSfcAndSecurityGroup_WhenChainedToSfcAndSgDe
Mockito.when(this.em.find(Mockito.eq(DistributedAppliance.class), Mockito.eq(VALID_ID_WITH_SFC)))
.thenReturn(da);
this.exception.expect(VmidcBrokerValidationException.class);
this.exception.expectMessage(
String.format(
"distributed appliance cannot be deleted which is currently referencing Service Function Chain '%s' and binded to a SecurityGroup(s) '%s'",
sfc.getName(), sg.getName()));
this.exception.expectMessage(String.format("Service Function Chain '%s' and binded to a Security Group(s) '%s'",
sfc.getName(), sg.getName()));

// Act
this.validator.validateAndLoad(createRequest(VALID_ID_WITH_SFC, false));
}

@Test
public void testValidateDAReferenceToSfcAndSecurityGroup_WhenChainedToSfcDeleteRequest_ThrowsValidationException()
public void testValidateAndLoad_WhenChainedToSfc_WhenSfcMode_ThrowsValidationException()
throws Exception {
// Arrange
final Long VALID_ID_WITH_SFC = 4l;
Expand All @@ -212,10 +213,7 @@ public void testValidateDAReferenceToSfcAndSecurityGroup_WhenChainedToSfcDeleteR
Mockito.when(em.find(Mockito.eq(DistributedAppliance.class), Mockito.eq(VALID_ID_WITH_SFC)))
.thenReturn(da);
this.exception.expect(VmidcBrokerValidationException.class);
this.exception.expectMessage(
String.format(
"distributed appliance cannot be deleted which is currently referencing Service Function Chain '%s'",
sfc.getName()));
this.exception.expectMessage(String.format("Service Function Chain '%s'",sfc.getName()));

// Act
this.validator.validateAndLoad(createRequest(VALID_ID_WITH_SFC, false));
Expand Down

0 comments on commit 14d1494

Please sign in to comment.