* Inside IP: 10.10.10.10
*/
// Mock the command
ConfigureStaticNatRulesOnLogicalRouterCommand cmd = mock(ConfigureStaticNatRulesOnLogicalRouterCommand.class);
StaticNatRuleTO rule = new StaticNatRuleTO(1,"11.11.11.11", null, null, "10.10.10.10", null, null, null, false, false);
List<StaticNatRuleTO> rules = new ArrayList<StaticNatRuleTO>();
rules.add(rule);
when(cmd.getRules()).thenReturn(rules);
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls
NatRule[] rulepair = _resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
rulepair[0].setUuid(UUID.randomUUID());
rulepair[1].setUuid(UUID.randomUUID());
when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
// Mock the api find call
@SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair));
when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
assertTrue(a.getResult());
verify(_nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
@Override
public boolean matches(Object argument) {
NatRule rule = (NatRule) argument;
if (rule.getType().equals("DestinationNatRule") &&
((DestinationNatRule)rule).getToDestinationIpAddress().equals("10.10.10.10")) {
return true;
}
if (rule.getType().equals("SourceNatRule") &&
((SourceNatRule)rule).getToSourceIpAddressMin().equals("11.11.11.11")) {
return true;
}
return false;
} }));