/*
 * 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.apache.aries.subsystem.core.internal;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.net.MalformedURLException;

import org.junit.Test;
import org.osgi.framework.Version;

public class LocationTest {
	@Test
	public void testAnyLocationString() {
		String locationStr = "anyLocation";
		Location location = null;
		try {
			location = new Location(locationStr);
		}
		catch (Throwable t) {
			t.printStackTrace();
			fail("Any location string must be supported");
		}
		assertNull("Wrong symbolic name", location.getSymbolicName());
		assertEquals("Wrong value", locationStr, location.getValue());
		assertNull("Wrong version", location.getVersion());
		try {
			location.open();
			fail("Opening a location that does not represent a URL should fail");
		}
		catch (MalformedURLException e) {
			// Okay
		}
		catch (Throwable t) {
			t.printStackTrace();
			fail("Wrong exception");
		}
	}

    @Test
    public void testSubsystemLocation() throws Exception {
        // In some cases the following location string is generated
        String locationString = "subsystem://?Subsystem-SymbolicName=org.osgi.service.subsystem.root&Subsystem-Version=1.2.3";

        Location location = new Location(locationString);
        assertEquals(locationString, location.getValue());
        assertEquals("org.osgi.service.subsystem.root", location.getSymbolicName());
        assertEquals(Version.parseVersion("1.2.3"), location.getVersion());
    }

    @Test
	public void testSubsystemLocationInvalid() throws Exception {
	    // In some cases the following location string is generated
	    String locationString = "subsystem://?Subsystem-SymbolicName=org.osgi.service.subsystem.root&Subsystem-Version=1.0.0!/my-subsystem@0.5.0";

	    Location location = new Location(locationString);
	    assertEquals(locationString, location.getValue());
	    assertNull(location.getSymbolicName());
	    assertNull(location.getVersion());
	}
}

@@ -1624,76 +1624,8 @@
 n %7B%0A
-        // In some cases the following location string is generated%0A
     
@@ -2039,25 +2039,28 @@
 %0A%0A    @Test%0A
-%09
+    
 public void 
@@ -2109,17 +2109,20 @@
 ption %7B%0A
-%09
+    
     // I
@@ -2177,17 +2177,20 @@
 nerated%0A
-%09
+    
     Stri
@@ -2325,17 +2325,20 @@
 .5.0%22;%0A%0A
-%09
+    
     Loca
@@ -2383,17 +2383,20 @@
 tring);%0A
-%09
+    
     asse
@@ -2438,25 +2438,28 @@
 etValue());%0A
-%09
+    
     assertNu
@@ -2490,17 +2490,20 @@
 ame());%0A
-%09
+    
     asse
@@ -2533,13 +2533,16 @@
 ion());%0A
-%09
+    
 %7D%0A%7D%0A

Fix tabs left in the code in a previous commit.