/*
 * Copyright 2012 Shared Learning Collaborative, LLC
 *
 * 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 org.slc.sli.modeling.wadl;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import junit.framework.TestCase;

import org.junit.Test;
import org.slc.sli.modeling.rest.ParamStyle;

/**
 * JUnit test for WadlSyntax class.
 * 
 * @author dholmes
 * 
 */
public class WadlSyntaxTestCase extends TestCase {

    @Test(expected = IllegalArgumentException.class)
    public void testDecodeParamStyle() {

        assertEquals(5, ParamStyle.values().length);

        assertEquals(ParamStyle.PLAIN, WadlSyntax.decodeParamStyle("plain"));
        assertEquals(ParamStyle.QUERY, WadlSyntax.decodeParamStyle("query"));
        assertEquals(ParamStyle.MATRIX, WadlSyntax.decodeParamStyle("matrix"));
        assertEquals(ParamStyle.HEADER, WadlSyntax.decodeParamStyle("header"));
        assertEquals(ParamStyle.TEMPLATE, WadlSyntax.decodeParamStyle("template"));

        assertNull(WadlSyntax.decodeParamStyle(null));

        assertEquals(ParamStyle.TEMPLATE, WadlSyntax.decodeParamStyle("foo"));
        fail();
    }

    public void testEncodeParamStyle() {

        assertEquals(5, ParamStyle.values().length);

        assertEquals("plain", WadlSyntax.encodeParamStyle(ParamStyle.PLAIN));
        assertEquals("query", WadlSyntax.encodeParamStyle(ParamStyle.QUERY));
        assertEquals("matrix", WadlSyntax.encodeParamStyle(ParamStyle.MATRIX));
        assertEquals("header", WadlSyntax.encodeParamStyle(ParamStyle.HEADER));
        assertEquals("template", WadlSyntax.encodeParamStyle(ParamStyle.TEMPLATE));

        assertNull(WadlSyntax.encodeParamStyle(null));
    }

    public void testEncodeStringList() {
        final ArrayList<String> mutableList = new ArrayList<String>();
        final List<String> immutableList = Collections.unmodifiableList(mutableList);

        assertEquals("", WadlSyntax.encodeStringList(immutableList));

        mutableList.add("a");

        assertEquals("a", WadlSyntax.encodeStringList(immutableList));

        mutableList.add("b");

        assertEquals("a b", WadlSyntax.encodeStringList(immutableList));

        mutableList.add("c");

        assertEquals("a b c", WadlSyntax.encodeStringList(immutableList));

        assertNull(WadlSyntax.encodeStringList(null));
    }

    public void testPrivateConstructor() throws Throwable {
        Constructor<?> constructor = WadlSyntax.class.getDeclaredConstructor((Class<?>[]) null);
        constructor.setAccessible(true);
        constructor.newInstance((Object[]) null);

    }
}

@@ -608,16 +608,17 @@
 e.%0A */%0A%0A
+%0A
 package 
@@ -803,31 +803,8 @@
 e;%0A%0A
-import org.junit.Test;%0A
 impo
@@ -887,17 +887,16 @@
 lass.%0A *
- 
 %0A * @aut
@@ -909,17 +909,16 @@
 olmes%0A *
- 
 %0A */%0Apub
@@ -970,61 +970,8 @@
  %7B%0A%0A
-    @Test(expected = IllegalArgumentException.class)%0A
     
@@ -1515,24 +1515,42 @@
 le(null));%0A%0A
+        try %7B%0A    
         asse
@@ -1628,16 +1628,20 @@
     
+    
 fail();%0A
     
@@ -1632,24 +1632,111 @@
     fail();%0A
+        %7D catch (final IllegalArgumentException e) %7B%0A            // Expected%0A        %7D%0A
     %7D%0A%0A    p

Fix unit test.