@Test public void testCreatePayload() { AddFirewallRuleToNicRequestBinder binder = new AddFirewallRuleToNicRequestBinder(); Firewall.Request.AddRulePayload payload = Firewall.Request.createAddRulePayload( "nic-id", ImmutableList.of( Firewall.Rule.builder() .name("name") .portRangeEnd(45678) .portRangeStart(12345) .protocol(Firewall.Protocol.TCP) .sourceIp("192.168.0.1") .sourceMac("aa:bb:cc:dd:ee:ff") .targetIp("192.168.0.2") .build() )); String actual = binder.createPayload(payload); assertNotNull(actual, "Binder returned null payload"); assertEquals(actual, expectedPayload); }
@Override protected String createPayload(Firewall.Request.AddRulePayload payload) { requestBuilder.append("<ws:addFirewallRulesToNic>") .append(format("<nicId>%s</nicId>", payload.nicId())); for (Firewall.Rule rule : payload.rules()) requestBuilder .append("<request>") .append(formatIfNotEmpty("<icmpCode>%s</icmpCode>", rule.icmpCode())) .append(formatIfNotEmpty("<icmpType>%s</icmpType>", rule.icmpType())) .append(formatIfNotEmpty("<name>%s</name>", rule.name())) .append(formatIfNotEmpty("<portRangeEnd>%s</portRangeEnd>", rule.portRangeEnd())) .append(formatIfNotEmpty("<portRangeStart>%s</portRangeStart>", rule.portRangeStart())) .append(formatIfNotEmpty("<protocol>%s</protocol>", rule.protocol())) .append(formatIfNotEmpty("<sourceIp>%s</sourceIp>", rule.sourceIp())) .append(formatIfNotEmpty("<sourceMac>%s</sourceMac>", rule.sourceMac())) .append(formatIfNotEmpty("<targetIp>%s</targetIp>", rule.targetIp())) .append("</request>"); requestBuilder.append("</ws:addFirewallRulesToNic>"); return requestBuilder.toString(); }
AddFirewallRuleToNicRequestBinder extends BaseProfitBricksRequestBinder<Firewall.Request.AddRulePayload> { @Override protected String createPayload(Firewall.Request.AddRulePayload payload) { requestBuilder.append("<ws:addFirewallRulesToNic>") .append(format("<nicId>%s</nicId>", payload.nicId())); for (Firewall.Rule rule : payload.rules()) requestBuilder .append("<request>") .append(formatIfNotEmpty("<icmpCode>%s</icmpCode>", rule.icmpCode())) .append(formatIfNotEmpty("<icmpType>%s</icmpType>", rule.icmpType())) .append(formatIfNotEmpty("<name>%s</name>", rule.name())) .append(formatIfNotEmpty("<portRangeEnd>%s</portRangeEnd>", rule.portRangeEnd())) .append(formatIfNotEmpty("<portRangeStart>%s</portRangeStart>", rule.portRangeStart())) .append(formatIfNotEmpty("<protocol>%s</protocol>", rule.protocol())) .append(formatIfNotEmpty("<sourceIp>%s</sourceIp>", rule.sourceIp())) .append(formatIfNotEmpty("<sourceMac>%s</sourceMac>", rule.sourceMac())) .append(formatIfNotEmpty("<targetIp>%s</targetIp>", rule.targetIp())) .append("</request>"); requestBuilder.append("</ws:addFirewallRulesToNic>"); return requestBuilder.toString(); } }
AddFirewallRuleToNicRequestBinder extends BaseProfitBricksRequestBinder<Firewall.Request.AddRulePayload> { @Override protected String createPayload(Firewall.Request.AddRulePayload payload) { requestBuilder.append("<ws:addFirewallRulesToNic>") .append(format("<nicId>%s</nicId>", payload.nicId())); for (Firewall.Rule rule : payload.rules()) requestBuilder .append("<request>") .append(formatIfNotEmpty("<icmpCode>%s</icmpCode>", rule.icmpCode())) .append(formatIfNotEmpty("<icmpType>%s</icmpType>", rule.icmpType())) .append(formatIfNotEmpty("<name>%s</name>", rule.name())) .append(formatIfNotEmpty("<portRangeEnd>%s</portRangeEnd>", rule.portRangeEnd())) .append(formatIfNotEmpty("<portRangeStart>%s</portRangeStart>", rule.portRangeStart())) .append(formatIfNotEmpty("<protocol>%s</protocol>", rule.protocol())) .append(formatIfNotEmpty("<sourceIp>%s</sourceIp>", rule.sourceIp())) .append(formatIfNotEmpty("<sourceMac>%s</sourceMac>", rule.sourceMac())) .append(formatIfNotEmpty("<targetIp>%s</targetIp>", rule.targetIp())) .append("</request>"); requestBuilder.append("</ws:addFirewallRulesToNic>"); return requestBuilder.toString(); } AddFirewallRuleToNicRequestBinder(); }
AddFirewallRuleToNicRequestBinder extends BaseProfitBricksRequestBinder<Firewall.Request.AddRulePayload> { @Override protected String createPayload(Firewall.Request.AddRulePayload payload) { requestBuilder.append("<ws:addFirewallRulesToNic>") .append(format("<nicId>%s</nicId>", payload.nicId())); for (Firewall.Rule rule : payload.rules()) requestBuilder .append("<request>") .append(formatIfNotEmpty("<icmpCode>%s</icmpCode>", rule.icmpCode())) .append(formatIfNotEmpty("<icmpType>%s</icmpType>", rule.icmpType())) .append(formatIfNotEmpty("<name>%s</name>", rule.name())) .append(formatIfNotEmpty("<portRangeEnd>%s</portRangeEnd>", rule.portRangeEnd())) .append(formatIfNotEmpty("<portRangeStart>%s</portRangeStart>", rule.portRangeStart())) .append(formatIfNotEmpty("<protocol>%s</protocol>", rule.protocol())) .append(formatIfNotEmpty("<sourceIp>%s</sourceIp>", rule.sourceIp())) .append(formatIfNotEmpty("<sourceMac>%s</sourceMac>", rule.sourceMac())) .append(formatIfNotEmpty("<targetIp>%s</targetIp>", rule.targetIp())) .append("</request>"); requestBuilder.append("</ws:addFirewallRulesToNic>"); return requestBuilder.toString(); } AddFirewallRuleToNicRequestBinder();  }
AddFirewallRuleToNicRequestBinder extends BaseProfitBricksRequestBinder<Firewall.Request.AddRulePayload> { @Override protected String createPayload(Firewall.Request.AddRulePayload payload) { requestBuilder.append("<ws:addFirewallRulesToNic>") .append(format("<nicId>%s</nicId>", payload.nicId())); for (Firewall.Rule rule : payload.rules()) requestBuilder .append("<request>") .append(formatIfNotEmpty("<icmpCode>%s</icmpCode>", rule.icmpCode())) .append(formatIfNotEmpty("<icmpType>%s</icmpType>", rule.icmpType())) .append(formatIfNotEmpty("<name>%s</name>", rule.name())) .append(formatIfNotEmpty("<portRangeEnd>%s</portRangeEnd>", rule.portRangeEnd())) .append(formatIfNotEmpty("<portRangeStart>%s</portRangeStart>", rule.portRangeStart())) .append(formatIfNotEmpty("<protocol>%s</protocol>", rule.protocol())) .append(formatIfNotEmpty("<sourceIp>%s</sourceIp>", rule.sourceIp())) .append(formatIfNotEmpty("<sourceMac>%s</sourceMac>", rule.sourceMac())) .append(formatIfNotEmpty("<targetIp>%s</targetIp>", rule.targetIp())) .append("</request>"); requestBuilder.append("</ws:addFirewallRulesToNic>"); return requestBuilder.toString(); } AddFirewallRuleToNicRequestBinder();   }