/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.sling.commons.osgi;

import junit.framework.TestCase;

/**
 * Tests for the manifest header parsing.
 */
public class ManifestHeaderTest extends TestCase {

    public void testNonExisting() {
        String header = null;
        final ManifestHeader entry = ManifestHeader.parse(header);
        assertNull(entry);
    }

    public void testSinglePath() {
        String header = "something";
        final ManifestHeader entry = ManifestHeader.parse(header);
        assertEquals(1, entry.getEntries().length);
        assertEquals(header, entry.getEntries()[0].getValue());
        assertEquals(0, entry.getEntries()[0].getAttributes().length);
        assertEquals(0, entry.getEntries()[0].getDirectives().length);
    }

    public void testSeveralPaths() {
        String header = "one,two,   three    ,\n   four, \n   five";
        final ManifestHeader entry = ManifestHeader.parse(header);
        assertEquals(5, entry.getEntries().length);
        assertEquals("one", entry.getEntries()[0].getValue());
        assertEquals(0, entry.getEntries()[0].getAttributes().length);
        assertEquals(0, entry.getEntries()[0].getDirectives().length);
        assertEquals("two", entry.getEntries()[1].getValue());
        assertEquals(0, entry.getEntries()[1].getAttributes().length);
        assertEquals(0, entry.getEntries()[1].getDirectives().length);
        assertEquals("three", entry.getEntries()[2].getValue());
        assertEquals(0, entry.getEntries()[2].getAttributes().length);
        assertEquals(0, entry.getEntries()[2].getDirectives().length);
        assertEquals("four", entry.getEntries()[3].getValue());
        assertEquals(0, entry.getEntries()[3].getAttributes().length);
        assertEquals(0, entry.getEntries()[3].getDirectives().length);
        assertEquals("five", entry.getEntries()[4].getValue());
        assertEquals(0, entry.getEntries()[4].getAttributes().length);
        assertEquals(0, entry.getEntries()[4].getDirectives().length);
    }

    public void testAttributes() {
        String header = "one;a=1;b=2";
        final ManifestHeader entry = ManifestHeader.parse(header);
        assertEquals(1, entry.getEntries().length);
        assertEquals("one", entry.getEntries()[0].getValue());
        assertEquals(2, entry.getEntries()[0].getAttributes().length);
        assertEquals(0, entry.getEntries()[0].getDirectives().length);
        assertEquals("a", entry.getEntries()[0].getAttributes()[0].getName());
        assertEquals("b", entry.getEntries()[0].getAttributes()[1].getName());
        assertEquals("1", entry.getEntries()[0].getAttributes()[0].getValue());
        assertEquals("2", entry.getEntries()[0].getAttributes()[1].getValue());
    }

    public void testDirectives() {
        String header = "one;a:=1;b:=2";
        final ManifestHeader entry = ManifestHeader.parse(header);
        assertEquals(1, entry.getEntries().length);
        assertEquals("one", entry.getEntries()[0].getValue());
        assertEquals(2, entry.getEntries()[0].getDirectives().length);
        assertEquals(0, entry.getEntries()[0].getAttributes().length);
        assertEquals("a", entry.getEntries()[0].getDirectives()[0].getName());
        assertEquals("b", entry.getEntries()[0].getDirectives()[1].getName());
        assertEquals("1", entry.getEntries()[0].getDirectives()[0].getValue());
        assertEquals("2", entry.getEntries()[0].getDirectives()[1].getValue());
    }
}

@@ -4255,11 +4255,1420 @@
 );%0A    %7D
+%0A%0A    public void testMultipleEntries() %7B%0A        String header = %22SLING-INF/content/etc;checkin:=true;path:=/etc,%5CnSLING-INF/content/libs;overwrite:=true;path:=/libs%22;%0A        final ManifestHeader entry = ManifestHeader.parse(header);%0A        assertEquals(2, entry.getEntries().length);%0A        assertEquals(%22SLING-INF/content/etc%22, entry.getEntries()%5B0%5D.getValue());%0A        assertEquals(2, entry.getEntries()%5B0%5D.getDirectives().length);%0A        assertEquals(0, entry.getEntries()%5B0%5D.getAttributes().length);%0A        assertEquals(%22checkin%22, entry.getEntries()%5B0%5D.getDirectives()%5B0%5D.getName());%0A        assertEquals(%22path%22, entry.getEntries()%5B0%5D.getDirectives()%5B1%5D.getName());%0A        assertEquals(%22true%22, entry.getEntries()%5B0%5D.getDirectives()%5B0%5D.getValue());%0A        assertEquals(%22/etc%22, entry.getEntries()%5B0%5D.getDirectives()%5B1%5D.getValue());%0A        assertEquals(%22SLING-INF/content/libs%22, entry.getEntries()%5B1%5D.getValue());%0A        assertEquals(2, entry.getEntries()%5B1%5D.getDirectives().length);%0A        assertEquals(0, entry.getEntries()%5B1%5D.getAttributes().length);%0A        assertEquals(%22overwrite%22, entry.getEntries()%5B1%5D.getDirectives()%5B0%5D.getName());%0A        assertEquals(%22path%22, entry.getEntries()%5B1%5D.getDirectives()%5B1%5D.getName());%0A        assertEquals(%22true%22, entry.getEntries()%5B1%5D.getDirectives()%5B0%5D.getValue());%0A        assertEquals(%22/libs%22, entry.getEntries()%5B1%5D.getDirectives()%5B1%5D.getValue());%0A    %7D
 %0A%7D%0A

Add a test case with several directives and multiple lines.