// Path: src/main/java/org/apache/camel/component/websocket/SignalkWebsocketComponent.java
// public class SignalkWebsocketComponent extends WebsocketComponent {
// 
// 	protected WebsocketComponentServlet createServlet(NodeSynchronization sync, String pathSpec, Map<String, WebsocketComponentServlet> servlets,
// 			ServletContextHandler handler) {
// 		SignalkWebSocketServlet servlet = new SignalkWebSocketServlet(sync);
// 		servlets.put(pathSpec, servlet);
// 		handler.addServlet(new ServletHolder(servlet), pathSpec);
// 		return servlet;
// 	}
// 
// }


import mjson.Json;
import nz.co.fortytwo.signalk.model.SignalKModel;
import nz.co.fortytwo.signalk.model.impl.SignalKModelFactory;
import nz.co.fortytwo.signalk.util.ConfigConstants;
import nz.co.fortytwo.signalk.util.JsonSerializer;
import nz.co.fortytwo.signalk.util.Util;
import org.apache.activemq.broker.BrokerService;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.websocket.SignalkWebsocketComponent;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.BeforeClass;
import static nz.co.fortytwo.signalk.util.SignalKConstants.FORMAT;
import static nz.co.fortytwo.signalk.util.SignalKConstants.GET;
import static nz.co.fortytwo.signalk.util.SignalKConstants.PATH;
import java.util.concurrent.CountDownLatch;
	public Json getList(String context, String path) {
		Json json = Json.read("{\"context\":\""+context+"\", \"list\": []}");
		Json sub = Json.object();
		sub.set("path",path);
		json.at("list").add(sub);
		logger.debug("Created json list: "+json);
		return json;
	}
	public Json getGet(String context, String path, String format) {
		Json json = Json.read("{\"context\":\"" + context + "\", \"get\": []}");
		Json sub = Json.object();
		sub.set(PATH, path);
		sub.set(FORMAT, format);
		json.at(GET).add(sub);
		logger.debug("Created json get: " + json);
		return json;
	}
	
	@Override
	protected RouteBuilder createRouteBuilder() {
	    try {
	    	try {
				//Util.getConfig();
				
				broker.start();
				logger.debug("Started broker");
				routeManager=new RouteManager(){
					@Override
					public void configure() throws Exception {
						if(CamelContextFactory.getInstance().getComponent("skWebsocket")==null){
// Path: src/main/java/org/apache/camel/component/websocket/SignalkWebsocketComponent.java
// public class SignalkWebsocketComponent extends WebsocketComponent {
// 
// 	protected WebsocketComponentServlet createServlet(NodeSynchronization sync, String pathSpec, Map<String, WebsocketComponentServlet> servlets,
// 			ServletContextHandler handler) {
// 		SignalkWebSocketServlet servlet = new SignalkWebSocketServlet(sync);
// 		servlets.put(pathSpec, servlet);
// 		handler.addServlet(new ServletHolder(servlet), pathSpec);
// 		return servlet;
// 	}
// 
// }


// Path: src/test/java/nz/co/fortytwo/signalk/server/SignalKCamelTestSupport.java
import mjson.Json;
import nz.co.fortytwo.signalk.model.SignalKModel;
import nz.co.fortytwo.signalk.model.impl.SignalKModelFactory;
import nz.co.fortytwo.signalk.util.ConfigConstants;
import nz.co.fortytwo.signalk.util.JsonSerializer;
import nz.co.fortytwo.signalk.util.Util;
import org.apache.activemq.broker.BrokerService;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.websocket.SignalkWebsocketComponent;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.BeforeClass;
import static nz.co.fortytwo.signalk.util.SignalKConstants.FORMAT;
import static nz.co.fortytwo.signalk.util.SignalKConstants.GET;
import static nz.co.fortytwo.signalk.util.SignalKConstants.PATH;
import java.util.concurrent.CountDownLatch;

	public Json getList(String context, String path) {
		Json json = Json.read("{\"context\":\""+context+"\", \"list\": []}");
		Json sub = Json.object();
		sub.set("path",path);
		json.at("list").add(sub);
		logger.debug("Created json list: "+json);
		return json;
	}
	public Json getGet(String context, String path, String format) {
		Json json = Json.read("{\"context\":\"" + context + "\", \"get\": []}");
		Json sub = Json.object();
		sub.set(PATH, path);
		sub.set(FORMAT, format);
		json.at(GET).add(sub);
		logger.debug("Created json get: " + json);
		return json;
	}
	
	@Override
	protected RouteBuilder createRouteBuilder() {
	    try {
	    	try {
				//Util.getConfig();
				
				broker.start();
				logger.debug("Started broker");
				routeManager=new RouteManager(){
					@Override
					public void configure() throws Exception {
						if(CamelContextFactory.getInstance().getComponent("skWebsocket")==null){
							CamelContextFactory.getInstance().addComponent("skWebsocket", new SignalkWebsocketComponent());