/*
 * Copyright 2017 Crown Copyright
 *
 * 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 stroom.xmlschema;


import org.junit.jupiter.api.Test;
import stroom.pipeline.xmlschema.XmlSchemaStore;
import stroom.test.AbstractCoreIntegrationTest;
import stroom.test.CommonTestControl;
import stroom.pipeline.xmlschema.FindXMLSchemaCriteria;
import stroom.xmlschema.shared.XmlSchemaDoc;

import javax.inject.Inject;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class TestXMLSchemaStoreImpl extends AbstractCoreIntegrationTest {
    @Inject
    private XmlSchemaStore xmlSchemaStore;
    @Inject
    private CommonTestControl commonTestControl;

    @Test
    void test() {
        // Import the schemas.
        commonTestControl.createRequiredXMLSchemas();

        // Now make sure we can find a resource that we expect to be there.
        FindXMLSchemaCriteria criteria = new FindXMLSchemaCriteria();

        List<XmlSchemaDoc> list = xmlSchemaStore.find(criteria).getValues();
        assertThat(list).isNotNull();
        assertThat(list.size() > 1).isTrue();

        criteria = new FindXMLSchemaCriteria();
        criteria.setNamespaceURI("event-logging:3");
        list = xmlSchemaStore.find(criteria).getValues();
        assertThat(list).isNotNull();
        assertThat(list.size()).isEqualTo(2);

        criteria = new FindXMLSchemaCriteria();
        criteria.setSystemId("file://event-logging-v3.0.0.xsd");
        list = xmlSchemaStore.find(criteria).getValues();
        assertThat(list).isNotNull();
        assertThat(list.size()).isEqualTo(1);

        criteria = new FindXMLSchemaCriteria();
        criteria.setSchemaGroup("EVENTS");
        list = xmlSchemaStore.find(criteria).getValues();
        assertThat(list).isNotNull();
        assertThat(list.size()).isEqualTo(2);
    }
}

@@ -635,34 +635,55 @@
 ort 
-org.junit.jupiter.api.Test
+stroom.pipeline.xmlschema.FindXMLSchemaCriteria
 ;%0Aim
@@ -825,33 +825,24 @@
 port stroom.
-pipeline.
 xmlschema.Fi
@@ -843,74 +843,120 @@
 ema.
-FindXMLSchemaCriteria;%0Aimport stroom.xmlschema.shared.XmlSchemaDoc
+shared.XmlSchemaDoc;%0A%0Aimport org.junit.jupiter.api.Test;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
 ;%0A%0Ai
@@ -1004,16 +1004,52 @@
 il.List;
+%0Aimport java.util.stream.Collectors;
 %0A%0Aimport
@@ -1168,16 +1168,114 @@
 nTest %7B%0A
+%0A    private static final Logger LOGGER = LoggerFactory.getLogger(TestXMLSchemaStoreImpl.class);%0A%0A
     @Inj
@@ -1957,32 +1957,33 @@
 a).getValues();%0A
+%0A
         assertTh
@@ -1986,37 +1986,389 @@
 rtThat(list)
-.isNotNull();
+%0A                .isNotNull();%0A%0A        LOGGER.info(%22Schemas:%5Cn%7B%7D%22, list.stream()%0A                .map(xmlSchemaDoc -%3E%0A                        xmlSchemaDoc.getNamespaceURI() + %22 %22%0A                                + xmlSchemaDoc.getSystemId() + %22 %22%0A                                + xmlSchemaDoc.getSchemaGroup())%0A                .collect(Collectors.joining(%22%5Cn%22)));%0A
 %0A        ass
@@ -2379,32 +2379,49 @@
 hat(list.size())
+%0A                
 .isEqualTo(2);%0A%0A
@@ -2415,17 +2415,17 @@
 EqualTo(
-2
+5
 );%0A%0A    
@@ -2607,32 +2607,49 @@
 assertThat(list)
+%0A                
 .isNotNull();%0A  
@@ -2669,32 +2669,49 @@
 hat(list.size())
+%0A                
 .isEqualTo(1);%0A%0A
@@ -2928,16 +2928,33 @@
 .size())
+%0A                
 .isEqual
@@ -2956,17 +2956,17 @@
 EqualTo(
-2
+5
 );%0A    %7D

Fix TestXMLSchemaStoreImpl