package io.silverspoon;

import io.silverspoon.bulldog.core.Signal;
import io.silverspoon.bulldog.core.gpio.DigitalOutput;
import io.silverspoon.bulldog.core.platform.Board;
import io.silverspoon.bulldog.core.platform.Platform;

import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Ignore;
import org.junit.Test;

public class BulldogComponentTest extends CamelTestSupport {

   private final String pinName = System.getProperty("test.pinName", "P1_11");
   private final String pinValue = System.getProperty("test.pinValue", "HIGH");

   @EndpointInject(uri = "mock:result")
   protected MockEndpoint mockEndpoint;

   @Produce(uri = "direct:start")
   protected ProducerTemplate template;

   @Test
   public void testGpio() throws Exception {
      MockEndpoint mock = getMockEndpoint("mock:result");
      mock.expectedMinimumMessageCount(1);

      assertMockEndpointsSatisfied();

      // assert pin value
      Board board = Platform.createBoard();
      DigitalOutput outputPin = board.getPin(pinName).as(DigitalOutput.class);

      Signal signal = Signal.fromString(pinValue);
      if (signal.equals(Signal.High)) {
         assertTrue(outputPin.isHigh());
      } else {
         assertTrue(outputPin.isLow());
      }
   }

   @Ignore
   public void testSPI() {
      // TODO: Implement with #35
   }

   @Ignore
   public void testI2C() {
      // TODO: Implement with #36
   }

   @Ignore
   public void testPWM() {
      // TODO: Implement with #38
   }

   @Override
   protected RouteBuilder createRouteBuilder() throws Exception {
      return new RouteBuilder() {
         public void configure() {
            from("direct:start").to(String.format("bulldog:gpio?pin=%s&value=%s", pinName, pinValue)).to("mock:result");
         }
      };
   }

   /*
    * Enable debugging
    */
   @Override
   public boolean isUseDebugger() {
      return true;
   }
}

@@ -1069,24 +1069,54 @@
 eCount(1);%0A%0A
+      template.sendBody(%22%22);%0A%0A
       assert
@@ -1173,16 +1173,106 @@
 ue%0A     
+ // TODO: Enable once https://github.com/px3/bulldog/issues/47 is fixed.%0A      /*%0A       *
  Board b
@@ -1307,16 +1307,19 @@
 );%0A     
+  *
  Digital
@@ -1384,22 +1384,34 @@
 class);%0A
+       * 
 %0A     
+  *
  Signal 
@@ -1458,61 +1458,23 @@
     
-if (signal.equals(Signal.High)) %7B%0A       
  
+*
  assert
-True
+Equals
 (out
@@ -1484,71 +1484,34 @@
 Pin.
-isHigh());%0A      %7D else %7B%0A         assertTrue(outputPin.isLow()
+getAppliedSignal(), signal
 );%0A 
@@ -1511,25 +1511,27 @@
 nal);%0A      
-%7D
+ */
 %0A   %7D%0A%0A   @I
@@ -2082,16 +2082,20 @@
 ebugging
+ IDE
 %0A    */%0A

Disable bulldog verification due to bulldog/#47