/*
 * Copyright 2015 Stefan Urech
 * 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 ch.halarious.core.examples;

import ch.halarious.core.*;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

/**
 * End-to-End-Test für die Serialisierung mit GSON
 */
public class GsonSerializerTest {

    private Gson gson;

    @Before
    public void before() {
        // GSON erstellen
        GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(HalResource.class, new HalSerializer());
        builder.registerTypeAdapter(HalResource.class, new HalDeserializer(TestResource.class));
        builder.setExclusionStrategies(new HalExclusionStrategy());
        this.gson = builder.create();
    }

    @Test
    @Ignore
    public void testEmbeddedList() {
        // Testdaten erstellen
        TestResource resource = new TestResource();
        resource.getResources().add(new TestResource());
        resource.getResources().add(new TestResource());

        // Test durchführen
        String result = gson.toJson(resource, HalResource.class);

        // Überprüfen
        Assert.assertEquals("{\"filledText\":\"test\",\"_links\":{\"self\":{\"href\":\"link\",\"title\":\"Test\"},\"reference\":{}},\"_embedded\":{\"test\":[{\"filledText\":\"test\",\"_links\":{\"self\":{\"href\":\"link\",\"title\":\"Test\"},\"reference\":{}}},{\"filledText\":\"test\",\"_links\":{\"self\":{\"href\":\"link\",\"title\":\"Test\"},\"reference\":{}}}]}}", result);
        System.out.println(result);
    }

    @Test
    @Ignore
    public void testEmbeddedListWithOneElement() {
        // Testdaten erstellen
        TestResource resource = new TestResource();
        resource.getResources().add(new TestResource());

        // Test durchführen
        String result = gson.toJson(resource, HalResource.class);

        // Überprüfen
        Assert.assertEquals("{\"filledText\":\"test\",\"_links\":{\"self\":{\"href\":\"link\",\"title\":\"Test\"},\"reference\":{}},\"_embedded\":{\"test\":[{\"filledText\":\"test\",\"_links\":{\"self\":{\"href\":\"link\",\"title\":\"Test\"},\"reference\":{}}}]}}", result);
        System.out.println(result);
    }
}

@@ -1345,36 +1345,24 @@
 %0A%0A    @Test%0A
-    @Ignore%0A
     public v
@@ -1382,24 +1382,24 @@
 dedList() %7B%0A
+
         // T
@@ -1761,32 +1761,49 @@
 %22,%5C%22_links%5C%22:%7B%5C%22
+reference%5C%22:%7B%7D,%5C%22
 self%5C%22:%7B%5C%22href%5C%22
@@ -1831,33 +1831,16 @@
 %22Test%5C%22%7D
-,%5C%22reference%5C%22:%7B%7D
 %7D,%5C%22_emb
@@ -1889,32 +1889,49 @@
 %22,%5C%22_links%5C%22:%7B%5C%22
+reference%5C%22:%7B%7D,%5C%22
 self%5C%22:%7B%5C%22href%5C%22
@@ -1959,33 +1959,16 @@
 %22Test%5C%22%7D
-,%5C%22reference%5C%22:%7B%7D
 %7D%7D,%7B%5C%22fi
@@ -1993,32 +1993,49 @@
 %22,%5C%22_links%5C%22:%7B%5C%22
+reference%5C%22:%7B%7D,%5C%22
 self%5C%22:%7B%5C%22href%5C%22
@@ -2063,33 +2063,16 @@
 %22Test%5C%22%7D
-,%5C%22reference%5C%22:%7B%7D
 %7D%7D%5D%7D%7D%22, 
@@ -2137,20 +2137,8 @@
 est%0A
-    @Ignore%0A
     
@@ -2502,32 +2502,49 @@
 %22,%5C%22_links%5C%22:%7B%5C%22
+reference%5C%22:%7B%7D,%5C%22
 self%5C%22:%7B%5C%22href%5C%22
@@ -2572,33 +2572,16 @@
 %22Test%5C%22%7D
-,%5C%22reference%5C%22:%7B%7D
 %7D,%5C%22_emb
@@ -2638,16 +2638,33 @@
 ks%5C%22:%7B%5C%22
+reference%5C%22:%7B%7D,%5C%22
 self%5C%22:%7B
@@ -2704,25 +2704,8 @@
 t%5C%22%7D
-,%5C%22reference%5C%22:%7B%7D
 %7D%7D%5D%7D

fix for #18