package au.csiro.ontology.snomed.refset.rf2;

import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.junit.Test;

public class ModuleDependencyRefsetTest {

    @Test
    public void test() {
        Logger log = Logger.getLogger(ModuleDependencyRefset.class);
        log.addAppender(new AppenderSkeleton(true) {

            @Override
            public boolean requiresLayout() {
                return false;
            }

            @Override
            public void close() {
            }

            @Override
            protected void append(LoggingEvent event) {
                final String message = String.valueOf(event.getMessage());
                if (!message.startsWith("MDRS entry for version:")) {
                    throw new AssertionError("Should not log: " + message);
                }
            }
        });
        Set<ModuleDependencyRow> members = new HashSet<ModuleDependencyRow>();
        members.add(new ModuleDependencyRow("a", "20010101", true, "A", "A", "B", "20010101", "10010101"));
        members.add(new ModuleDependencyRow("b", "10010101", true, "B", "A", "C", "10010101", "10010101"));
        members.add(new ModuleDependencyRow("c", "20010101", true, "A", "A", "C", "20010101", "10010101"));
        new ModuleDependencyRefset(members);
    }

    @Test(expected=AssertionError.class)
    public void testIncomplete() {
        Logger log = Logger.getLogger(ModuleDependencyRefset.class);
        log.addAppender(new AppenderSkeleton(true) {

            @Override
            public boolean requiresLayout() {
                return false;
            }

            @Override
            public void close() {
            }

            @Override
            protected void append(LoggingEvent event) {
                throw new AssertionError("Should not log: " + event.getMessage());
            }
        });
        Set<ModuleDependencyRow> members = new HashSet<ModuleDependencyRow>();
        members.add(new ModuleDependencyRow("a", "20010101", true, "A", "A", "B", "20010101", "10010101"));
        members.add(new ModuleDependencyRow("b", "10010101", true, "B", "A", "C", "10010101", "10010101"));
        new ModuleDependencyRefset(members);
    }

}

@@ -269,16 +269,65 @@
 etTest %7B
+%0A    final String MDRS_ID = %22900000000000534007%22;
 %0A%0A    @T
@@ -416,32 +416,66 @@
 yRefset.class);%0A
+        log.removeAllAppenders();%0A
         log.addA
@@ -1182,35 +1182,39 @@
 01%22, true, %22A%22, 
-%22A%22
+MDRS_ID
 , %22B%22, %2220010101
@@ -1294,35 +1294,39 @@
 01%22, true, %22B%22, 
-%22A%22
+MDRS_ID
 , %22C%22, %2210010101
@@ -1414,19 +1414,23 @@
 e, %22A%22, 
-%22A%22
+MDRS_ID
 , %22C%22, %22
@@ -1525,30 +1525,32 @@
 xpected=
-AssertionError
+RuntimeException
 .class)%0A
@@ -1645,32 +1645,66 @@
 yRefset.class);%0A
+        log.removeAllAppenders();%0A
         log.addA
@@ -1995,32 +1995,347 @@
 gEvent event) %7B%0A
+                final String message = String.valueOf(event.getMessage());%0A                if (message.startsWith(%22Added implied transitive dependency%22)) %7B%0A                    throw new RuntimeException(%22Should not log: %22 + message);%0A                %7D else if (!message.startsWith(%22MDRS entry for version:%22)) %7B%0A    
                 
@@ -2380,36 +2380,43 @@
 og: %22 + 
-event.getMessage());
+message);%0A                %7D
 %0A       
@@ -2585,19 +2585,23 @@
 e, %22A%22, 
-%22A%22
+MDRS_ID
 , %22B%22, %22
@@ -2697,19 +2697,23 @@
 e, %22B%22, 
-%22A%22
+MDRS_ID
 , %22C%22, %22

fix tests to account for MDRS reading tweaks