// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/AddedMessage.java
// public class AddedMessage {
// 
//     private String collection;
// 
//     private String id;
// 
//     private JsonObject fields;
// 
//     public String getCollection() {
//         return collection;
//     }
// 
//     public void setCollection(String collection) {
//         this.collection = collection;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public JsonObject getFields() {
//         return fields;
//     }
// 
//     public void setFields(JsonObject fields) {
//         this.fields = fields;
//     }
// 
//     @Override
//     public String toString() {
//         return "Added{" +
//                 "collection='" + collection + '\'' +
//                 ", id='" + id + '\'' +
//                 ", fields=" + fields +
//                 '}';
//     }
// }


import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import io.advantageous.ddp.*;
import io.advantageous.ddp.subscription.message.AddedMessage;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import javax.websocket.*;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/*
 * Copyright (C) 2014. Geoffrey Chandler.
 *
 * Licensed 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 io.advantageous.ddp.subscription;




public class MapSubscriptionAdapterTest {

    private static final String CONNECTED_MESSAGE = "{\"msg\":\"connected\",\"session\":\"DNLpTnL8ZPTTizPvC\"}";

    private static final String[] ADDED_MESSAGES = {
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"uA6nsqCHnmjT3xmsm\",\"fields\":{\"name\":\"Ian Serlin\",\"total\":45.00}}",
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"GkXcKNamHLesd57wi\",\"fields\":{\"name\":\"Geoff Chandler\",\"total\":50.00}}",
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"odje77pej68MiSdPB\",\"fields\":{\"name\":\"Daniel Baron\",\"total\":255.00}}",
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"uWz3rCXYAuevqX2bJ\",\"fields\":{\"name\":\"Foo\",\"total\":5}}"
    };

    private WebSocketContainer wsContainer;

    private Session mockSession;

    @Before
    public void setup() throws Exception {
        this.wsContainer = mock(WebSocketContainer.class);

        this.mockSession = mock(Session.class);
        when(mockSession.isOpen()).thenReturn(true);

        RemoteEndpoint.Async asyncRemote = mock(RemoteEndpoint.Async.class);
        when(mockSession.getAsyncRemote()).thenReturn(asyncRemote);

    }

    @Test
    @SuppressWarnings("unchecked")
    public void testAdded() throws Exception {

        final Map<String, Map<String, Object>> localData = new HashMap<>();

        final DDPMessageEndpoint client = new DDPMessageEndpointImpl(wsContainer, new JsonMessageConverter());

        final ObjectConverter converter = new JsonObjectConverter();

        final SubscriptionAdapter adapter = new MapSubscriptionAdapter(client, converter, localData);

        final Set<Object> results = new HashSet<>();

// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/AddedMessage.java
// public class AddedMessage {
// 
//     private String collection;
// 
//     private String id;
// 
//     private JsonObject fields;
// 
//     public String getCollection() {
//         return collection;
//     }
// 
//     public void setCollection(String collection) {
//         this.collection = collection;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public JsonObject getFields() {
//         return fields;
//     }
// 
//     public void setFields(JsonObject fields) {
//         this.fields = fields;
//     }
// 
//     @Override
//     public String toString() {
//         return "Added{" +
//                 "collection='" + collection + '\'' +
//                 ", id='" + id + '\'' +
//                 ", fields=" + fields +
//                 '}';
//     }
// }


// Path: ddp-client/src/test/java/io/advantageous/ddp/subscription/MapSubscriptionAdapterTest.java
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import io.advantageous.ddp.*;
import io.advantageous.ddp.subscription.message.AddedMessage;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import javax.websocket.*;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/*
 * Copyright (C) 2014. Geoffrey Chandler.
 *
 * Licensed 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 io.advantageous.ddp.subscription;




public class MapSubscriptionAdapterTest {

    private static final String CONNECTED_MESSAGE = "{\"msg\":\"connected\",\"session\":\"DNLpTnL8ZPTTizPvC\"}";

    private static final String[] ADDED_MESSAGES = {
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"uA6nsqCHnmjT3xmsm\",\"fields\":{\"name\":\"Ian Serlin\",\"total\":45.00}}",
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"GkXcKNamHLesd57wi\",\"fields\":{\"name\":\"Geoff Chandler\",\"total\":50.00}}",
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"odje77pej68MiSdPB\",\"fields\":{\"name\":\"Daniel Baron\",\"total\":255.00}}",
            "{\"msg\":\"added\",\"collection\":\"tabs\",\"id\":\"uWz3rCXYAuevqX2bJ\",\"fields\":{\"name\":\"Foo\",\"total\":5}}"
    };

    private WebSocketContainer wsContainer;

    private Session mockSession;

    @Before
    public void setup() throws Exception {
        this.wsContainer = mock(WebSocketContainer.class);

        this.mockSession = mock(Session.class);
        when(mockSession.isOpen()).thenReturn(true);

        RemoteEndpoint.Async asyncRemote = mock(RemoteEndpoint.Async.class);
        when(mockSession.getAsyncRemote()).thenReturn(asyncRemote);

    }

    @Test
    @SuppressWarnings("unchecked")
    public void testAdded() throws Exception {

        final Map<String, Map<String, Object>> localData = new HashMap<>();

        final DDPMessageEndpoint client = new DDPMessageEndpointImpl(wsContainer, new JsonMessageConverter());

        final ObjectConverter converter = new JsonObjectConverter();

        final SubscriptionAdapter adapter = new MapSubscriptionAdapter(client, converter, localData);

        final Set<Object> results = new HashSet<>();

        client.registerHandler(AddedMessage.class, DDPMessageHandler.Phase.AFTER_UPDATE, message -> {