You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by de...@apache.org on 2016/02/19 16:33:22 UTC

[12/35] jclouds git commit: JCLOUDS-702: JCloud ProfitBricks provider - NIC & Firewall API

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/FirewallResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/FirewallResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/FirewallResponseHandler.java
new file mode 100644
index 0000000..dae5191
--- /dev/null
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/FirewallResponseHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.http.parser.firewall;
+
+import com.google.inject.Inject;
+
+import org.jclouds.profitbricks.domain.Firewall;
+import org.jclouds.profitbricks.http.parser.firewall.rule.FirewallRuleListResponseHandler;
+import org.xml.sax.SAXException;
+
+public class FirewallResponseHandler extends BaseFirewallResponseHandler<Firewall> {
+
+   private boolean done = false;
+
+   @Inject
+   FirewallResponseHandler(FirewallRuleListResponseHandler firewallRuleListResponseHandler) {
+      super(firewallRuleListResponseHandler);
+   }
+
+   @Override
+   public void endElement(String uri, String localName, String qName) throws SAXException {
+      if (done)
+         return;
+
+      if (useFirewallRuleParser)
+         firewallRuleListResponseHandler.endElement(uri, localName, qName);
+      else {
+         setPropertyOnEndTag(qName);
+         if ("return".equals(qName)) {
+            done = true;
+            builder.rules(firewallRuleListResponseHandler.getResult());
+         }
+         clearTextBuffer();
+      }
+
+      if ("firewallRules".equals(qName))
+         useFirewallRuleParser = false;
+   }
+
+   @Override
+   public void reset() {
+      this.builder = Firewall.builder();
+   }
+
+   @Override
+   public Firewall getResult() {
+      return builder.build();
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/BaseFirewallRuleResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/BaseFirewallRuleResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/BaseFirewallRuleResponseHandler.java
new file mode 100644
index 0000000..9461f46
--- /dev/null
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/BaseFirewallRuleResponseHandler.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.http.parser.firewall.rule;
+
+import org.jclouds.profitbricks.domain.Firewall;
+import org.jclouds.profitbricks.domain.Firewall.Protocol;
+
+import com.google.inject.Inject;
+
+import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
+
+public abstract class BaseFirewallRuleResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
+
+   protected Firewall.Rule.Builder builder;
+
+   @Inject
+   BaseFirewallRuleResponseHandler() {
+      this.builder = Firewall.Rule.builder();
+   }
+
+   @Override
+   protected void setPropertyOnEndTag(String qName) {
+      if ("firewallRuleId".equals(qName))
+         builder.id(textToStringValue());
+      else if ("name".equals(qName))
+         builder.name(textToStringValue());
+      else if ("portRangeEnd".equals(qName))
+         builder.portRangeEnd(textToIntValue());
+      else if ("portRangeStart".equals(qName))
+         builder.portRangeStart(textToIntValue());
+      else if ("protocol".equals(qName))
+         builder.protocol(Protocol.fromValue(textToStringValue()));
+      else if ("sourceIp".equals(qName))
+         builder.sourceIp(textToStringValue());
+      else if ("sourceMac".equals(qName))
+         builder.sourceMac(textToStringValue());
+      else if ("targetIp".equals(qName))
+         builder.targetIp(textToStringValue());
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/FirewallRuleListResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/FirewallRuleListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/FirewallRuleListResponseHandler.java
new file mode 100644
index 0000000..3085839
--- /dev/null
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/firewall/rule/FirewallRuleListResponseHandler.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.http.parser.firewall.rule;
+
+import java.util.List;
+
+import org.jclouds.profitbricks.domain.Firewall.Rule;
+import org.xml.sax.SAXException;
+
+import com.google.common.collect.Lists;
+
+public class FirewallRuleListResponseHandler extends BaseFirewallRuleResponseHandler<List<Rule>> {
+
+   private List<Rule> rules;
+
+   FirewallRuleListResponseHandler() {
+      this.rules = Lists.newArrayList();
+   }
+
+   @Override
+   public void endElement(String uri, String localName, String qName) throws SAXException {
+      setPropertyOnEndTag(qName);
+
+      if ("firewallRules".equals(qName))
+         rules.add(builder.build());
+      clearTextBuffer();
+
+   }
+
+   @Override
+   public void reset() {
+      this.rules = Lists.newArrayList();
+   }
+
+   @Override
+   public List<Rule> getResult() {
+      return rules;
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/BaseNicResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/BaseNicResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/BaseNicResponseHandler.java
new file mode 100644
index 0000000..83efca3
--- /dev/null
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/BaseNicResponseHandler.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.http.parser.nic;
+
+import com.google.inject.Inject;
+
+import org.jclouds.profitbricks.domain.Nic;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
+import org.jclouds.profitbricks.http.parser.firewall.FirewallResponseHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+public abstract class BaseNicResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
+
+   protected final FirewallResponseHandler firewallResponseHandler;
+
+   protected boolean useFirewallParser = false;
+   protected Nic.Builder builder;
+
+   @Inject
+   BaseNicResponseHandler(FirewallResponseHandler firewallResponseHandler) {
+      this.builder = Nic.builder();
+      this.firewallResponseHandler = firewallResponseHandler;
+   }
+
+   @Override
+   public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+      if ("firewall".equals(qName))
+         useFirewallParser = true;
+      if (useFirewallParser)
+         firewallResponseHandler.startElement(uri, localName, qName, attributes);
+   }
+
+   @Override
+   public void characters(char[] ch, int start, int length) {
+      if (useFirewallParser)
+         firewallResponseHandler.characters(ch, start, length);
+      else
+         super.characters(ch, start, length);
+   }
+
+   @Override
+   protected void setPropertyOnEndTag(String qName) {
+      if ("dataCenterId".equals(qName))
+         builder.dataCenterId(textToStringValue());
+      else if ("nicName".equals(qName))
+         builder.name(textToStringValue());
+      else if ("nicId".equals(qName))
+         builder.id(textToStringValue());
+      else if ("lanId".equals(qName))
+         builder.lanId(textToIntValue());
+      else if ("internetAccess".equals(qName))
+         builder.internetAccess(textToBooleanValue());
+      else if ("serverId".equals(qName))
+         builder.serverId(textToStringValue());
+      else if ("ips".equals(qName))
+         builder.ip(textToStringValue());
+      else if ("macAddress".equals(qName))
+         builder.macAddress(textToStringValue());
+      else if ("dhcpActive".equals(qName))
+         builder.dhcpActive(textToBooleanValue());
+      else if ("gatewayIp".equals(qName))
+         builder.gatewayIp(textToStringValue());
+      else if ("provisioningState".equals(qName))
+         builder.state(ProvisioningState.fromValue(textToStringValue()));
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicListResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicListResponseHandler.java
new file mode 100644
index 0000000..3d17c97
--- /dev/null
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicListResponseHandler.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.http.parser.nic;
+
+import autovalue.shaded.com.google.common.common.collect.Lists;
+import com.google.inject.Inject;
+import org.jclouds.profitbricks.domain.Nic;
+import org.xml.sax.SAXException;
+
+import java.util.List;
+import org.jclouds.profitbricks.http.parser.firewall.FirewallResponseHandler;
+
+public class NicListResponseHandler extends BaseNicResponseHandler<List<Nic>> {
+
+   private List<Nic> nics;
+
+   @Inject
+   public NicListResponseHandler(FirewallResponseHandler firewallResponseHandler) {
+      super(firewallResponseHandler);
+      this.nics = Lists.newArrayList();
+   }
+
+   @Override
+   public void endElement(String uri, String localName, String qName) throws SAXException {
+      if (useFirewallParser)
+         firewallResponseHandler.endElement(uri, localName, qName);
+      else {
+         setPropertyOnEndTag(qName);
+         if ("return".equals(qName) || "nics".equals(qName)) {
+            nics.add(builder
+                    .firewall(firewallResponseHandler.getResult())
+                    .build());
+            builder = Nic.builder();
+         }
+         clearTextBuffer();
+      }
+
+      if ("firewall".equals(qName))
+         useFirewallParser = false;
+   }
+
+   @Override
+   public void reset() {
+      this.nics = Lists.newArrayList();
+   }
+
+   @Override
+   public List<Nic> getResult() {
+      return nics;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicResponseHandler.java
new file mode 100644
index 0000000..690ecc1
--- /dev/null
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/nic/NicResponseHandler.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.http.parser.nic;
+
+import com.google.inject.Inject;
+import org.jclouds.profitbricks.domain.Nic;
+import org.jclouds.profitbricks.http.parser.firewall.FirewallResponseHandler;
+import org.xml.sax.SAXException;
+
+public class NicResponseHandler extends BaseNicResponseHandler<Nic> {
+
+   private boolean done = false;
+
+   @Inject
+   public NicResponseHandler(FirewallResponseHandler firewallResponseHandler) {
+      super(firewallResponseHandler);
+   }
+
+   @Override
+   public void endElement(String uri, String localName, String qName) throws SAXException {
+      if (done)
+         return;
+
+      if (useFirewallParser)
+         firewallResponseHandler.endElement(uri, localName, qName);
+      else {
+         setPropertyOnEndTag(qName);
+         if ("return".equals(qName)) {
+            done = true;
+            builder.firewall(firewallResponseHandler.getResult());
+            firewallResponseHandler.reset();
+         }
+         clearTextBuffer();
+      }
+
+      if ("firewall".equals(qName))
+         useFirewallParser = false;
+   }
+
+   @Override
+   public Nic getResult() {
+      return builder.build();
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java
index 356d218..69a34b1 100644
--- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java
@@ -28,19 +28,57 @@ import org.jclouds.profitbricks.domain.OsType;
 import org.jclouds.profitbricks.domain.ProvisioningState;
 import org.jclouds.profitbricks.domain.Server;
 import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
+import org.jclouds.profitbricks.http.parser.nic.NicListResponseHandler;
+import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
 
 public abstract class BaseServerResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
 
+   protected final StorageListResponseHandler storageListResponseHandler;
+   protected final NicListResponseHandler nicListResponseHandler;
+
    protected Server.DescribingBuilder builder;
 
    protected final DateCodec dateCodec;
 
+   protected boolean useStorageParser = false;
+   protected boolean useNicParser = false;
+
    @Inject
-   BaseServerResponseHandler(DateCodecFactory dateCodec) {
+   BaseServerResponseHandler(DateCodecFactory dateCodec, StorageListResponseHandler storageListResponseHandler,
+           NicListResponseHandler nicListResponseHandler) {
       this.dateCodec = dateCodec.iso8601();
+      this.storageListResponseHandler = storageListResponseHandler;
+      this.nicListResponseHandler = nicListResponseHandler;
       this.builder = Server.builder();
    }
 
+   @Override
+   public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+      if ("connectedStorages".equals(qName))
+         useStorageParser = true;
+      else if ("nics".equals(qName))
+         useNicParser = true;
+
+      if (useStorageParser)
+         storageListResponseHandler.startElement(uri, localName, qName, attributes);
+      else if (useNicParser)
+         nicListResponseHandler.startElement(uri, localName, qName, attributes);
+      else
+         super.startElement(uri, localName, qName, attributes);
+   }
+
+   @Override
+   public void characters(char[] ch, int start, int length) {
+      if (useStorageParser)
+         storageListResponseHandler.characters(ch, start, length);
+      else if (useNicParser)
+         nicListResponseHandler.characters(ch, start, length);
+      else
+         super.characters(ch, start, length);
+   }
+
    protected final Date textToIso8601Date() {
       return dateCodec.toDate(textToStringValue());
    }

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java
index 3dc6e6e..68ee696 100644
--- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java
@@ -17,8 +17,11 @@
 package org.jclouds.profitbricks.http.parser.server;
 
 import com.google.inject.Inject;
+
 import org.jclouds.date.DateCodecFactory;
 import org.jclouds.profitbricks.domain.Server;
+import org.jclouds.profitbricks.http.parser.nic.NicListResponseHandler;
+import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
 import org.xml.sax.SAXException;
 
 public class ServerInfoResponseHandler extends BaseServerResponseHandler<Server> {
@@ -26,18 +29,35 @@ public class ServerInfoResponseHandler extends BaseServerResponseHandler<Server>
    private boolean done = false;
 
    @Inject
-   ServerInfoResponseHandler(DateCodecFactory dateCodec) {
-      super(dateCodec);
+   ServerInfoResponseHandler(DateCodecFactory dateCodec, StorageListResponseHandler storageListResponseHandler,
+           NicListResponseHandler nicListResponseHandler) {
+      super(dateCodec, storageListResponseHandler, nicListResponseHandler);
    }
 
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
       if (done)
          return;
-      setPropertyOnEndTag(qName);
-      if ("return".equals(qName))
-         done = true;
-      clearTextBuffer();
+
+      if (useStorageParser)
+         storageListResponseHandler.endElement(uri, localName, qName);
+      else if (useNicParser)
+         nicListResponseHandler.endElement(uri, localName, qName);
+      else {
+         setPropertyOnEndTag(qName);
+         if ("return".equals(qName)) {
+            done = true;
+            builder
+                    .storages(storageListResponseHandler.getResult())
+                    .nics(nicListResponseHandler.getResult());
+         }
+         clearTextBuffer();
+      }
+
+      if ("connectedStorages".equals(qName))
+         useStorageParser = false;
+      else if ("nics".equals(qName))
+         useNicParser = false;
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java
index f0fcd3f..d7d50ab 100644
--- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java
@@ -18,29 +18,57 @@ package org.jclouds.profitbricks.http.parser.server;
 
 import com.google.common.collect.Lists;
 import com.google.inject.Inject;
+
 import java.util.List;
+
 import org.jclouds.date.DateCodecFactory;
 import org.jclouds.profitbricks.domain.Server;
+import org.jclouds.profitbricks.http.parser.nic.NicListResponseHandler;
+import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
 import org.xml.sax.SAXException;
 
 public class ServerListResponseHandler extends BaseServerResponseHandler<List<Server>> {
 
-   private final List<Server> servers;
+   private List<Server> servers;
 
    @Inject
-   ServerListResponseHandler(DateCodecFactory dateCodec) {
-      super(dateCodec);
+   ServerListResponseHandler(DateCodecFactory dateCodec, StorageListResponseHandler storageListResponseHandler,
+           NicListResponseHandler nicListResponseHandler) {
+      super(dateCodec, storageListResponseHandler, nicListResponseHandler);
       this.servers = Lists.newArrayList();
    }
 
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
-      setPropertyOnEndTag(qName);
-      if ("return".equals(qName)) {
-         servers.add(builder.build());
-         builder = Server.builder();
+
+      if (useStorageParser)
+         storageListResponseHandler.endElement(uri, localName, qName);
+      else if (useNicParser)
+         nicListResponseHandler.endElement(uri, localName, qName);
+      else {
+         setPropertyOnEndTag(qName);
+         if ("return".equals(qName) || "servers".equals(qName)) {
+            servers.add(builder
+                    .storages(storageListResponseHandler.getResult())
+                    .nics(nicListResponseHandler.getResult())
+                    .build());
+            storageListResponseHandler.reset();
+            nicListResponseHandler.reset();
+
+            builder = Server.builder();
+         }
+         clearTextBuffer();
       }
-      clearTextBuffer();
+
+      if ("connectedStorages".equals(qName))
+         useStorageParser = false;
+      else if ("nics".equals(qName))
+         useNicParser = false;
+   }
+
+   @Override
+   public void reset() {
+      this.servers = Lists.newArrayList();
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java
index fe5e3fa..d590c80 100644
--- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java
@@ -25,7 +25,7 @@ import org.xml.sax.SAXException;
 
 public class StorageListResponseHandler extends BaseStorageResponseHandler<List<Storage>> {
 
-   private final List<Storage> storages;
+   private List<Storage> storages;
 
    @Inject
    StorageListResponseHandler(DateCodecFactory dateCodec) {
@@ -36,7 +36,7 @@ public class StorageListResponseHandler extends BaseStorageResponseHandler<List<
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
       setPropertyOnEndTag(qName);
-      if ("return".equals(qName)) {
+      if ("return".equals(qName) || "connectedStorages".equals(qName) || "storages".equals(qName)) {
          storages.add(builder
                  .serverIds(serverIds)
                  .build());
@@ -47,6 +47,11 @@ public class StorageListResponseHandler extends BaseStorageResponseHandler<List<
    }
 
    @Override
+   public void reset() {
+      this.storages = Lists.newArrayList();
+   }
+
+   @Override
    public List<Storage> getResult() {
       return storages;
    }

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/main/java/org/jclouds/profitbricks/util/MacAddresses.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/util/MacAddresses.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/util/MacAddresses.java
new file mode 100644
index 0000000..5725e4b
--- /dev/null
+++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/util/MacAddresses.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.util;
+
+import java.util.regex.Pattern;
+
+public class MacAddresses {
+
+   private static final String MAC_ADDR_FORMAT = "^([0-9a-f]{2}[:]){5}([0-9a-f]{2})$";
+   private static final Pattern MAC_ADDR_PATTERN = Pattern.compile(MAC_ADDR_FORMAT);
+
+   public static boolean isMacAddress(String in) {
+      return MAC_ADDR_PATTERN.matcher(in).matches();
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/AddFirewallRuleToNicRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/AddFirewallRuleToNicRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/AddFirewallRuleToNicRequestBinderTest.java
new file mode 100644
index 0000000..daedc36
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/AddFirewallRuleToNicRequestBinderTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.binder.firewall;
+
+import org.jclouds.profitbricks.domain.Firewall;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import org.jclouds.profitbricks.domain.Firewall.Protocol;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "AddFirewallRuleToNicRequestBinderTest")
+public class AddFirewallRuleToNicRequestBinderTest {
+
+   @Test
+   public void testCreatePayload() {
+      AddFirewallRuleToNicRequestBinder binder = new AddFirewallRuleToNicRequestBinder();
+
+      Firewall.Request.AddRulePayload payload = Firewall.Request.ruleAddingBuilder()
+              .nicId("nic-id")
+              .newRule()
+              .name("name")
+              .portRangeEnd(45678)
+              .portRangeStart(12345)
+              .protocol(Protocol.TCP)
+              .sourceIp("192.168.0.1")
+              .sourceMac("aa:bb:cc:dd:ee:ff")
+              .targetIp("192.168.0.2")
+              .endRule()
+              .build();
+
+      String actual = binder.createPayload(payload);
+      assertNotNull(actual, "Binder returned null payload");
+      assertEquals(expectedPayload, actual);
+   }
+
+   private final String expectedPayload = ("  <ws:addFirewallRulesToNic>\n"
+           + "        <nicId>nic-id</nicId>\n"
+           + "            <request>\n"
+           + "                <name>name</name>\n"
+           + "                <portRangeEnd>45678</portRangeEnd>\n"
+           + "                <portRangeStart>12345</portRangeStart>\n"
+           + "                <protocol>TCP</protocol>\n"
+           + "                <sourceIp>192.168.0.1</sourceIp>\n"
+           + "                <sourceMac>aa:bb:cc:dd:ee:ff</sourceMac>\n"
+           + "                <targetIp>192.168.0.2</targetIp>\n"
+           + "            </request>\n"
+           + "        </ws:addFirewallRulesToNic>").replaceAll("\\s+", "");
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/FirewallBinderTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/FirewallBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/FirewallBinderTest.java
new file mode 100644
index 0000000..e32b788
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/firewall/FirewallBinderTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.binder.firewall;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.jclouds.profitbricks.binder.firewall.FirewallBinder.ActivateFirewallRequestBinder;
+import org.jclouds.profitbricks.binder.firewall.FirewallBinder.DeactivateFirewallRequestBinder;
+import org.jclouds.profitbricks.binder.firewall.FirewallBinder.DeleteFirewallRequestBinder;
+import org.jclouds.profitbricks.binder.firewall.FirewallBinder.RemoveFirewallRuleRequestBinder;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "FirewallBinderTest")
+public class FirewallBinderTest {
+
+   @Test
+   public void testActivateFirewallBindPayload() {
+      ActivateFirewallRequestBinder binder = new ActivateFirewallRequestBinder();
+
+      List<String> payload = ImmutableList.of(
+              "firewall-id-1",
+              "firewall-id-2",
+              "firewall-id-3",
+              "firewall-id-4"
+      );
+
+      String actual = binder.createPayload(payload);
+      assertNotNull(actual, "Binder returned null payload");
+
+      String expected = ("<ws:activateFirewalls>\n"
+              + "         <firewallIds>firewall-id-1</firewallIds>\n"
+              + "         <firewallIds>firewall-id-2</firewallIds>\n"
+              + "         <firewallIds>firewall-id-3</firewallIds>\n"
+              + "         <firewallIds>firewall-id-4</firewallIds>\n"
+              + "      </ws:activateFirewalls>").replaceAll("\\s+", "");
+
+      assertEquals(actual, expected);
+   }
+
+   @Test
+   public void testDeactivateFirewallBindPayload() {
+      DeactivateFirewallRequestBinder binder = new DeactivateFirewallRequestBinder();
+
+      List<String> payload = ImmutableList.of(
+              "firewall-id-1",
+              "firewall-id-2",
+              "firewall-id-3",
+              "firewall-id-4"
+      );
+
+      String actual = binder.createPayload(payload);
+      assertNotNull(actual, "Binder returned null payload");
+
+      String expected = ("<ws:deactivateFirewalls>\n"
+              + "         <firewallIds>firewall-id-1</firewallIds>\n"
+              + "         <firewallIds>firewall-id-2</firewallIds>\n"
+              + "         <firewallIds>firewall-id-3</firewallIds>\n"
+              + "         <firewallIds>firewall-id-4</firewallIds>\n"
+              + "      </ws:deactivateFirewalls>").replaceAll("\\s+", "");
+
+      assertEquals(actual, expected);
+   }
+
+   @Test
+   public void testDeleteFirewallBindPayload() {
+      DeleteFirewallRequestBinder binder = new DeleteFirewallRequestBinder();
+
+      List<String> payload = ImmutableList.of(
+              "firewall-id-1",
+              "firewall-id-2",
+              "firewall-id-3",
+              "firewall-id-4"
+      );
+
+      String actual = binder.createPayload(payload);
+      assertNotNull(actual, "Binder returned null payload");
+
+      String expected = ("<ws:deleteFirewalls>\n"
+              + "         <firewallIds>firewall-id-1</firewallIds>\n"
+              + "         <firewallIds>firewall-id-2</firewallIds>\n"
+              + "         <firewallIds>firewall-id-3</firewallIds>\n"
+              + "         <firewallIds>firewall-id-4</firewallIds>\n"
+              + "      </ws:deleteFirewalls>").replaceAll("\\s+", "");
+
+      assertEquals(actual, expected);
+   }
+
+   @Test
+   public void testRemoveFirewallRuleBindPayload() {
+      RemoveFirewallRuleRequestBinder binder = new RemoveFirewallRuleRequestBinder();
+
+      List<String> payload = ImmutableList.of(
+              "firewall-rule-id-1",
+              "firewall-rule-id-2",
+              "firewall-rule-id-3",
+              "firewall-rule-id-4"
+      );
+
+      String actual = binder.createPayload(payload);
+      assertNotNull(actual, "Binder returned null payload");
+
+      String expected = ("<ws:removeFirewallRules>\n"
+              + "         <firewallRuleIds>firewall-rule-id-1</firewallRuleIds>\n"
+              + "         <firewallRuleIds>firewall-rule-id-2</firewallRuleIds>\n"
+              + "         <firewallRuleIds>firewall-rule-id-3</firewallRuleIds>\n"
+              + "         <firewallRuleIds>firewall-rule-id-4</firewallRuleIds>\n"
+              + "      </ws:removeFirewallRules>").replaceAll("\\s+", "");
+
+      assertEquals(actual, expected);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/CreateNicRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/CreateNicRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/CreateNicRequestBinderTest.java
new file mode 100644
index 0000000..8e2630d
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/CreateNicRequestBinderTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.binder.nic;
+
+import org.jclouds.profitbricks.domain.Nic;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "CreateNicRequestBinderTest")
+public class CreateNicRequestBinderTest {
+
+   @Test
+   public void testCreatePayload() {
+      CreateNicRequestBinder binder = new CreateNicRequestBinder();
+
+      Nic.Request.CreatePayload payload = Nic.Request.creatingBuilder()
+              .ip("192.168.0.1")
+              .name("nic-name")
+              .dhcpActive(true)
+              .serverId("server-id")
+              .lanId(1)
+              .build();
+
+      String actual = binder.createPayload(payload);
+      assertNotNull(actual, "Binder returned null payload");
+      assertEquals(expectedPayload, actual);
+   }
+
+   private final String expectedPayload = ("<ws:createNic>\n"
+           + "            <request>\n"
+           + "                <ip>192.168.0.1</ip>\n"
+           + "                <nicName>nic-name</nicName>\n"
+           + "                <dhcpActive>true</dhcpActive>\n"
+           + "                <serverId>server-id</serverId>\n"
+           + "                <lanId>1</lanId>\n"
+           + "            </request>\n"
+           + "        </ws:createNic>").replaceAll("\\s+", "");
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/SetInternetAccessBinderTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/SetInternetAccessBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/SetInternetAccessBinderTest.java
new file mode 100644
index 0000000..c499c73
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/SetInternetAccessBinderTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.binder.nic;
+
+import org.jclouds.profitbricks.domain.Nic;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "SetInternetAccessBinderTest")
+public class SetInternetAccessBinderTest {
+
+   @Test
+   public void testCreatePayload() {
+      SetInternetAccessBinder binder = new SetInternetAccessBinder();
+
+      Nic.Request.SetInternetAccessPayload payload = Nic.Request.setInternetAccessBuilder()
+              .dataCenterId("datacenter-id")
+              .internetAccess(true)
+              .lanId(1)
+              .build();
+
+      String actual = binder.createPayload(payload);
+
+      assertNotNull(actual, "Binder returned null payload");
+      assertEquals(expectedPayload, actual);
+   }
+
+   private final String expectedPayload = (" <ws:setInternetAccess>\n"
+           + "                <dataCenterId>datacenter-id</dataCenterId>\n"
+           + "                <lanId>1</lanId>\n"
+           + "                <internetAccess>true</internetAccess>\n"
+           + "        </ws:setInternetAccess>").replaceAll("\\s+", "");
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/UpdateNicRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/UpdateNicRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/UpdateNicRequestBinderTest.java
new file mode 100644
index 0000000..298fea7
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/nic/UpdateNicRequestBinderTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.binder.nic;
+
+import org.jclouds.profitbricks.domain.Nic;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "UpdateNicRequestBinderTest")
+public class UpdateNicRequestBinderTest {
+
+   @Test
+   public void testCreatePayload() {
+      UpdateNicRequestBinder binder = new UpdateNicRequestBinder();
+
+      Nic.Request.UpdatePayload payload = Nic.Request.updatingBuilder()
+              .id("nic-id")
+              .ip("192.168.0.1")
+              .name("nic-name")
+              .dhcpActive(true)
+              .lanId(1)
+              .build();
+
+      String actual = binder.createPayload(payload);
+
+      assertNotNull(actual, "Binder returned null payload");
+      assertEquals(expectedPayload, actual);
+   }
+
+   private final String expectedPayload = (" <ws:updateNic>\n"
+           + "            <request>\n"
+           + "                <nicId>nic-id</nicId>\n"
+           + "                <ip>192.168.0.1</ip>\n"
+           + "                <nicName>nic-name</nicName>\n"
+           + "                <dhcpActive>true</dhcpActive>\n"
+           + "                <lanId>1</lanId>\n"
+           + "            </request>\n"
+           + "        </ws:updateNic>").replaceAll("\\s+", "");
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java
new file mode 100644
index 0000000..af29eae
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.domain;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "FirewallRuleBuilderTest")
+public class FirewallRuleBuilderTest {
+
+   private final String _name = "rule-name";
+   private final Integer _portRangeEnd = 45678;
+   private final Integer _portRangeStart = 12345;
+   private final Firewall.Protocol _protocol = Firewall.Protocol.TCP;
+   private final String _sourceIp = "192.168.0.1";
+   private final String _sourceMac = "aa:bb:cc:dd:ee:ff";
+   private final String _targetIp = "192.168.0.2";
+
+   private final Integer _icmpType = 2;
+   private final Integer _icmpCode = 24;
+
+   @Test
+   public void testAutoValueFirewallRulePropertiesSettingCorrectly() {
+      Firewall.Rule actual = Firewall.Rule.builder()
+              .name(_name)
+              .portRangeEnd(_portRangeEnd)
+              .portRangeStart(_portRangeStart)
+              .protocol(_protocol)
+              .sourceIp(_sourceIp)
+              .sourceMac(_sourceMac)
+              .targetIp(_targetIp)
+              .build();
+
+      assertEquals(actual.name(), _name);
+      assertEquals(actual.portRangeEnd(), _portRangeEnd);
+      assertEquals(actual.portRangeStart(), _portRangeStart);
+      assertEquals(actual.protocol(), _protocol);
+      assertEquals(actual.sourceIp(), _sourceIp);
+      assertEquals(actual.sourceMac(), _sourceMac);
+      assertEquals(actual.targetIp(), _targetIp);
+   }
+
+   @Test
+   public void testAutoValueFirewallRuleWithIcmpPropertiesSettingCorrectly() {
+      Firewall.RuleWithIcmp actual = Firewall.RuleWithIcmp.builder()
+              .name(_name)
+              .icmpCode(_icmpCode)
+              .icmpType(_icmpType)
+              .protocol(Firewall.Protocol.ICMP)
+              .sourceIp(_sourceIp)
+              .sourceMac(_sourceMac)
+              .targetIp(_targetIp)
+              .build();
+
+      assertEquals(actual.name(), _name);
+      assertNull(actual.portRangeEnd());
+      assertNull(actual.portRangeStart());
+      assertEquals(actual.protocol(), Firewall.Protocol.ICMP);
+      assertEquals(actual.sourceIp(), _sourceIp);
+      assertEquals(actual.sourceMac(), _sourceMac);
+      assertEquals(actual.targetIp(), _targetIp);
+      assertEquals(actual.icmpCode(), _icmpCode);
+      assertEquals(actual.icmpType(), _icmpType);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java
new file mode 100644
index 0000000..78e7dbd
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.features;
+
+import com.google.common.collect.Iterables;
+
+import java.util.List;
+
+import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
+import org.jclouds.profitbricks.domain.Firewall;
+import org.jclouds.profitbricks.domain.Nic;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.concurrent.TimeUnit;
+
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusAware;
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusPollingPredicate;
+import org.jclouds.profitbricks.domain.Firewall.Protocol;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.util.Predicates2;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+
+import autovalue.shaded.com.google.common.common.collect.ImmutableList;
+
+@Test(groups = "live", testName = "FirewallApiLiveTest", singleThreaded = true)
+public class FirewallApiLiveTest extends BaseProfitBricksLiveTest {
+
+   private Predicate<String> waitUntilAvailable;
+   private Nic nic;
+
+   private Firewall createdFirewall;
+   private Firewall.Rule createdFirewallRule;
+
+   @Override
+   protected void initialize() {
+      super.initialize();
+      List<Nic> nics = api.nicApi().getAllNics();
+      assertFalse(nics.isEmpty(), "Must atleast have 1 NIC available for firewall testing.");
+
+      this.nic = Iterables.tryFind(nics, new Predicate<Nic>() {
+
+         @Override
+         public boolean apply(Nic input) {
+            return input.state() == ProvisioningState.AVAILABLE;
+         }
+      }).orNull();
+
+      assertNotNull(nic, "No available NIC for firewall testing was found.");
+
+      this.waitUntilAvailable = Predicates2.retry(
+              new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.NIC, ProvisioningState.AVAILABLE),
+              2l * 60l, 2l, TimeUnit.SECONDS);
+   }
+
+   @Test
+   public void testAddFirewallRuleToNic() {
+      Firewall firewall = api.firewallApi().addFirewallRuleToNic(
+              Firewall.Request.ruleAddingBuilder()
+              .nicId(nic.id())
+              .newRule()
+              .name("test-rule-tcp")
+              .protocol(Protocol.TCP)
+              .endRule()
+              .build());
+
+      assertNotNull(firewall);
+      assertNotNull(firewall.rules());
+
+      waitUntilAvailable.apply(nic.id());
+      createdFirewall = firewall;
+      createdFirewallRule = Iterables.getOnlyElement(firewall.rules());
+   }
+
+   @Test(dependsOnMethods = "testAddFirewallRuleToNic")
+   public void testGetAllFirewalls() {
+      List<Firewall> firewalls = api.firewallApi().getAllFirewalls();
+
+      assertNotNull(firewalls);
+      assertFalse(firewalls.isEmpty());
+   }
+
+   @Test(dependsOnMethods = "testAddFirewallRuleToNic")
+   public void testGetFirewall() {
+      Firewall firewall = api.firewallApi().getFirewall(createdFirewall.id());
+
+      assertNotNull(firewall);
+      assertEquals(createdFirewall.id(), firewall.id());
+   }
+
+   @Test(dependsOnMethods = "testAddFirewallRuleToNic")
+   public void testActivateFirewall() {
+      boolean result = api.firewallApi().activateFirewall(ImmutableList.of(createdFirewall.id()));
+
+      waitUntilAvailable.apply(nic.id());
+
+      assertTrue(result);
+   }
+
+   @Test(dependsOnMethods = "testActivateFirewall")
+   void testDeactivateFirewall() {
+      boolean result = api.firewallApi().deactivateFirewall(ImmutableList.of(createdFirewall.id()));
+
+      waitUntilAvailable.apply(nic.id());
+
+      assertTrue(result);
+   }
+
+   @Test(dependsOnMethods = "testActivateFirewall")
+   void testRemoveFirewallRule() {
+      boolean result = api.firewallApi().removeFirewallRules(ImmutableList.of(createdFirewallRule.id()));
+
+      waitUntilAvailable.apply(nic.id());
+
+      assertTrue(result);
+   }
+
+   @AfterClass(alwaysRun = true)
+   public void testDeleteFirewall() {
+      if (createdFirewall != null) {
+         boolean result = api.firewallApi().deleteFirewall(ImmutableList.of(createdFirewall.id()));
+
+         assertTrue(result, "Created firewall was not deleted.");
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java
new file mode 100644
index 0000000..17ec324
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java
@@ -0,0 +1,324 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.features;
+
+import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+
+import java.util.List;
+
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.Firewall;
+import org.jclouds.profitbricks.domain.Firewall.Protocol;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "live", testName = "FirewallApiMockTest", singleThreaded = true)
+public class FirewallApiMockTest extends BaseProfitBricksMockTest {
+
+   @Test
+   public void testGetAllFirewalls() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewalls.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+
+      FirewallApi api = pbApi.firewallApi();
+
+      try {
+         List<Firewall> firewalls = api.getAllFirewalls();
+         assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllFirewalls/>");
+         assertNotNull(firewalls);
+         assertEquals(firewalls.size(), 2);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+
+      FirewallApi api = pbApi.firewallApi();
+
+      String id = "firewall-id";
+      String firewallruleid = "firewall-rule-id";
+
+      String content = "<ws:getFirewall><firewallId>" + id + "</firewallId></ws:getFirewall>";
+
+      try {
+         Firewall firewall = api.getFirewall(id);
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertNotNull(firewall);
+         assertEquals(firewall.id(), id);
+         assertFalse(firewall.rules().isEmpty());
+         assertEquals(firewall.rules().get(0).id(), firewallruleid);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetNonExistingFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String id = "firewall-id";
+
+      try {
+         Firewall firewall = api.getFirewall(id);
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNull(firewall);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testAddFirewallRuleToNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-addtonic.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String content = "<ws:addFirewallRulesToNic>"
+              + "<nicId>nic-id</nicId>"
+              + "<request>"
+              + "<name>name</name>"
+              + "<portRangeEnd>45678</portRangeEnd>"
+              + "<portRangeStart>12345</portRangeStart>"
+              + "<protocol>TCP</protocol>"
+              + "<sourceIp>192.168.0.1</sourceIp>"
+              + "<sourceMac>aa:bb:cc:dd:ee:ff</sourceMac>"
+              + "<targetIp>192.168.0.2</targetIp>"
+              + "</request>"
+              + "</ws:addFirewallRulesToNic>";
+      try {
+         Firewall.Request.AddRulePayload payload = Firewall.Request.ruleAddingBuilder()
+                 .nicId("nic-id")
+                 .newRule()
+                 .name("name")
+                 .portRangeEnd(45678)
+                 .portRangeStart(12345)
+                 .protocol(Protocol.TCP)
+                 .sourceIp("192.168.0.1")
+                 .sourceMac("aa:bb:cc:dd:ee:ff")
+                 .targetIp("192.168.0.2")
+                 .endRule()
+                 .build();
+         Firewall response = api.addFirewallRuleToNic(payload);
+
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertNotNull(response);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testRemoveFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-remove.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallId = "12345";
+      String content = "<ws:removeFirewallRules>"
+              + "<firewallRuleIds>" + firewallId + "</firewallRuleIds>"
+              + "</ws:removeFirewallRules>";
+
+      try {
+         boolean result = api.removeFirewallRules(ImmutableList.of(firewallId));
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertTrue(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testRemoveNonExitingFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallRuleId = "12345";
+
+      try {
+         boolean result = api.removeFirewallRules(ImmutableList.of(firewallRuleId));
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertFalse(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testActivateFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-activate.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallId = "12345";
+      String content = "<ws:activateFirewalls>"
+              + "<firewallIds>" + firewallId + "</firewallIds>"
+              + "</ws:activateFirewalls>";
+
+      try {
+         boolean result = api.activateFirewall(ImmutableList.of(firewallId));
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertTrue(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testActivateNonExitingFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallId = "12345";
+
+      try {
+         boolean result = api.activateFirewall(ImmutableList.of(firewallId));
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertFalse(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeactivateFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-deactivate.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallId = "12345";
+      String content = "<ws:deactivateFirewalls>"
+              + "<firewallIds>" + firewallId + "</firewallIds>"
+              + "</ws:deactivateFirewalls>";
+
+      try {
+         boolean result = api.deactivateFirewall(ImmutableList.of(firewallId));
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertTrue(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeactivateNonExitingFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallId = "12345";
+
+      try {
+         boolean result = api.deactivateFirewall(ImmutableList.of(firewallId));
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertFalse(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeleteFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-delete.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallId = "12345";
+      String content = "<ws:deleteFirewalls>"
+              + "<firewallIds>" + firewallId + "</firewallIds>"
+              + "</ws:deleteFirewalls>";
+
+      try {
+         boolean result = api.deleteFirewall(ImmutableList.of(firewallId));
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertTrue(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeleteNonExitingFirewall() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      FirewallApi api = pbApi.firewallApi();
+
+      String firewallId = "12345";
+
+      try {
+         boolean result = api.deleteFirewall(ImmutableList.of(firewallId));
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertFalse(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiLiveTest.java
new file mode 100644
index 0000000..fbbef8b
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiLiveTest.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import com.google.common.collect.Iterables;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusAware;
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusPollingPredicate;
+import org.jclouds.profitbricks.domain.Nic;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.domain.Server;
+import org.jclouds.util.Predicates2;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+
+@Test(groups = "live", testName = "NicApiLiveTest", singleThreaded = true)
+public class NicApiLiveTest extends BaseProfitBricksLiveTest {
+
+   private Predicate<String> waitUntilAvailable;
+   private Server server;
+   private Nic createdNic;
+
+   @Override
+   protected void initialize() {
+      super.initialize();
+      List<Server> servers = api.serverApi().getAllServers();
+      assertFalse(servers.isEmpty(), "Must atleast have 1 server available for NIC testing.");
+
+      this.server = Iterables.tryFind(servers, new Predicate<Server>() {
+
+         @Override
+         public boolean apply(Server input) {
+            return input.state() == ProvisioningState.AVAILABLE;
+         }
+      }).orNull();
+
+      this.waitUntilAvailable = Predicates2.retry(
+              new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.NIC, ProvisioningState.AVAILABLE),
+              2l * 60l, 2l, TimeUnit.SECONDS);
+   }
+
+   @Test
+   public void testCreateNic() {
+      Nic.Request.CreatePayload payload = Nic.Request.creatingBuilder()
+              .name("name nr1")
+              .dhcpActive(true)
+              .serverId(server.id())
+              .lanId(1)
+              .build();
+
+      Nic nic = api.nicApi().createNic(payload);
+      assertNotNull(nic);
+
+      waitUntilAvailable.apply(nic.id());
+      this.createdNic = nic;
+   }
+
+   @Test(dependsOnMethods = "testCreateNic")
+   public void testGetAllNics() {
+      List<Nic> nics = api.nicApi().getAllNics();
+
+      assertNotNull(nics);
+   }
+
+   @Test(dependsOnMethods = "testCreateNic")
+   public void testGetNic() {
+      Nic nic = api.nicApi().getNic(createdNic.id());
+
+      assertNotNull(nic);
+      assertEquals(nic.id(), createdNic.id());
+   }
+
+   @Test(dependsOnMethods = "testCreateNic")
+   public void testUpdateNic() {
+      Nic.Request.UpdatePayload payload = Nic.Request.updatingBuilder()
+              .name("name nr2")
+              .id(createdNic.id())
+              .build();
+
+      Nic updatedNic = api.nicApi().updateNic(payload);
+      assertNotNull(updatedNic);
+      waitUntilAvailable.apply(payload.id());
+
+      updatedNic = api.nicApi().getNic(payload.id());
+
+      assertEquals(updatedNic.name(), payload.name());
+   }
+
+   @Test(dependsOnMethods = "testUpdateNic")
+   public void testSetInternetAccess() {
+
+      Nic.Request.SetInternetAccessPayload payload = Nic.Request.setInternetAccessBuilder()
+              .dataCenterId(createdNic.dataCenterId())
+              .lanId(1)
+              .internetAccess(true)
+              .build();
+
+      Nic result = api.nicApi().setInternetAccess(payload);
+      assertNotNull(result);
+   }
+
+   @AfterClass(alwaysRun = true)
+   public void testDeleteNic() {
+      if (createdNic != null) {
+         boolean result = api.nicApi().deleteNic(createdNic.id());
+
+         assertTrue(result, "Created test NIC was not deleted.");
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java
new file mode 100644
index 0000000..0e01e2c
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.profitbricks.features;
+
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+import java.util.List;
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.Nic;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "NicApiMockTest")
+
+public class NicApiMockTest extends BaseProfitBricksMockTest {
+
+   @Test
+   public void testGetNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+
+      String id = "12345678-abcd-efgh-ijkl-987654321000";
+
+      String content = "<ws:getNic><nicId>" + id + "</nicId></ws:getNic>";
+      try {
+         Nic nic = api.getNic(id);
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertNotNull(nic);
+         assertEquals(nic.id(), id);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetNonExistingNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+
+      String id = "nonexisting-nic-id";
+
+      try {
+         Nic nic = api.getNic(id);
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNull(nic);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetAllNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nics.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+      try {
+         List<Nic> nics = api.getAllNics();
+         assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllNic/>");
+         assertNotNull(nics);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testCreateNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-create.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+
+      String content = "<ws:createNic>"
+              + "<request>"
+              + "<ip>192.168.0.1</ip>"
+              + "<nicName>nic-name</nicName>"
+              + "<dhcpActive>true</dhcpActive>"
+              + "<serverId>server-id</serverId>"
+              + "<lanId>1</lanId>"
+              + "</request>"
+              + "</ws:createNic>";
+
+      try {
+         Nic nic = api.createNic(
+                 Nic.Request.creatingBuilder()
+                 .ip("192.168.0.1")
+                 .name("nic-name")
+                 .dhcpActive(true)
+                 .lanId(1)
+                 .serverId("server-id")
+                 .build());
+
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertNotNull(nic.id());
+
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testUpdateNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-update.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+
+      String content = "<ws:updateNic>"
+              + "<request>"
+              + "<nicId>nic-id</nicId>"
+              + "<ip>ip</ip>"
+              + "<nicName>nic-name</nicName>"
+              + "<dhcpActive>true</dhcpActive>"
+              + "<lanId>1</lanId>"
+              + "</request>"
+              + "</ws:updateNic>";
+      try {
+         Nic nic = api.updateNic(Nic.Request.UpdatePayload.create("nic-id", "ip", "nic-name", true, 1));
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testSetInternetAccess() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-internetaccess.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+
+      String content = "<ws:setInternetAccess>"
+              + "<dataCenterId>datacenter-id</dataCenterId>"
+              + "<lanId>1</lanId>"
+              + "<internetAccess>true</internetAccess>"
+              + "</ws:setInternetAccess>";
+      try {
+         Nic nic = api.setInternetAccess(Nic.Request.SetInternetAccessPayload.create("datacenter-id", 1, true));
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeleteNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-delete.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+
+      String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+
+      String content = "<ws:deleteNic><nicId>" + id + "</nicId></ws:deleteNic>";
+
+      try {
+         boolean result = api.deleteNic(id);
+         assertRequestHasCommonProperties(server.takeRequest(), content);
+         assertTrue(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeleteNonExistingNic() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      NicApi api = pbApi.nicApi();
+
+      String id = "nonexisting-nic-id";
+
+      try {
+         boolean result = api.deleteNic(id);
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertFalse(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de2e5e01/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
index f9827b3..e2ee87e 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
@@ -24,7 +24,9 @@ import org.jclouds.date.DateCodecFactory;
 import org.jclouds.http.functions.ParseSax;
 import org.jclouds.profitbricks.domain.AvailabilityZone;
 import org.jclouds.profitbricks.domain.DataCenter;
+import org.jclouds.profitbricks.domain.Firewall;
 import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.Nic;
 import org.jclouds.profitbricks.domain.OsType;
 import org.jclouds.profitbricks.domain.ProvisioningState;
 import org.jclouds.profitbricks.domain.Server;
@@ -63,7 +65,7 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<D
               .location(Location.US_LAS)
               .servers(ImmutableList.<Server>of(
                               Server.builder()
-                              .id("12345678-abcd-efgh-ijkl-987654321000")
+                              .id("qqqqqqqq-wwww-eeee-rrrr-tttttttttttt")
                               .name("jnode1")
                               .cores(4)
                               .ram(4096)
@@ -80,8 +82,43 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<D
                               .isNicHotUnPlug(true)
                               .isDiscVirtioHotPlug(true)
                               .isDiscVirtioHotUnPlug(true)
+                              .storages(ImmutableList.<Storage>of(
+                                              Storage.builder()
+                                              .bootDevice(Boolean.TRUE)
+                                              .id("ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh")
+                                              .busType(Storage.BusType.VIRTIO)
+                                              .deviceNumber(1)
+                                              .size(40f)
+                                              .name("jnode1-disk1")
+                                              .build()
+                                      )
+                              )
+                              .nics(ImmutableList.<Nic>of(
+                                              Nic.builder()
+                                              .dataCenterId("12345678-abcd-efgh-ijkl-987654321000")
+                                              .id("zzzzzzzz-xxxx-cccc-vvvv-bbbbbbbbbbbb")
+                                              .lanId(1)
+                                              .internetAccess(true)
+                                              .serverId("qqqqqqqq-wwww-eeee-rrrr-tttttttttttt")
+                                              .ip("202.94.38.12")
+                                              .macAddress("02:01:09:cd:f0:b0")
+                                              .firewall(
+                                                      Firewall.builder()
+                                                      .active(false)
+                                                      .id("llllllll-kkkk-jjjj-hhhh-gggggggggggg")
+                                                      .nicId("zzzzzzzz-xxxx-cccc-vvvv-bbbbbbbbbbbb")
+                                                      .state(ProvisioningState.AVAILABLE)
+                                                      .build()
+                                              )
+                                              .dhcpActive(true)
+                                              .gatewayIp("202.94.38.1")
+                                              .state(ProvisioningState.AVAILABLE)
+                                              .build()
+                                      )
+                              )
                               .build()
-                      ))
+                      )
+              )
               .storages(ImmutableList.<Storage>of(
                               Storage.builder()
                               .id("ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh")
@@ -90,6 +127,9 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<D
                               .state(ProvisioningState.AVAILABLE)
                               .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
                               .lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z"))
+                              .serverIds(ImmutableList.of(
+                                              "qqqqqqqq-wwww-eeee-rrrr-tttttttttttt"
+                                      ))
                               .build()
                       ))
               .build();