package eu.europa.esig.dss.validation.policy.bbb;

import java.util.Date;

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import eu.europa.esig.dss.EN319102.bbb.sav.SignatureAcceptanceValidation;
import eu.europa.esig.dss.EN319102.policy.ValidationPolicy;
import eu.europa.esig.dss.EN319102.policy.ValidationPolicy.Context;
import eu.europa.esig.dss.jaxb.detailedreport.XmlConstraint;
import eu.europa.esig.dss.jaxb.detailedreport.XmlSAV;
import eu.europa.esig.dss.validation.policy.bbb.util.TestDiagnosticDataGenerator;
import eu.europa.esig.dss.validation.policy.bbb.util.TestPolicyGenerator;
import eu.europa.esig.dss.validation.policy.rules.Indication;
import eu.europa.esig.dss.validation.policy.rules.MessageTag;
import eu.europa.esig.dss.validation.policy.rules.SubIndication;
import eu.europa.esig.dss.validation.report.DiagnosticData;
import eu.europa.esig.jaxb.policy.Level;
import eu.europa.esig.jaxb.policy.LevelConstraint;

public class SignatureAcceptanceValidationTest {
	
	private static final Logger logger = LoggerFactory.getLogger(SignatureAcceptanceValidationTest.class);

	@Test
	public void testWithBasicDataAndBasicPolicy() throws Exception {
		DiagnosticData data = TestDiagnosticDataGenerator.generateSimpleDiagnosticData();
		
		LevelConstraint failLevel = new LevelConstraint();
		failLevel.setLevel(Level.FAIL);
		
		SignatureAcceptanceValidation validation = new SignatureAcceptanceValidation(data, new Date(), data.getSignatures().get(0), Context.SIGNATURE, TestPolicyGenerator.generatePolicy());
		XmlSAV sav = validation.execute();
		
		for(XmlConstraint constraint : sav.getConstraints()) {
			logger.info(constraint.getName().getValue() + " : " + constraint.getStatus());
		}
		
		Assert.assertEquals(Indication.VALID, sav.getConclusion().getIndication());
	}
	
	@Test
	public void testWithBasicDataButCertifiedRolesAsFailLevel() throws Exception {
		DiagnosticData data = TestDiagnosticDataGenerator.generateSimpleDiagnosticData();
		
		ValidationPolicy policy = TestPolicyGenerator.generatePolicy();
		policy.getCertifiedRolesConstraint().setLevel(Level.FAIL);
		
		LevelConstraint failLevel = new LevelConstraint();
		failLevel.setLevel(Level.FAIL);
		
		SignatureAcceptanceValidation validation = new SignatureAcceptanceValidation(data, new Date(), data.getSignatures().get(0), Context.SIGNATURE, policy);
		XmlSAV sav = validation.execute();
		
		for(XmlConstraint constraint : sav.getConstraints()) {
			logger.info(constraint.getName().getValue() + " : " + constraint.getStatus());
		}
		
		Assert.assertEquals(Indication.INVALID, sav.getConclusion().getIndication());
		Assert.assertEquals(SubIndication.SIG_CONSTRAINTS_FAILURE, sav.getConclusion().getSubIndication());
		Assert.assertEquals(MessageTag.BBB_SAV_ICERRM_ANS.getMessage(), sav.getConclusion().getError().getValue());
	}
}

@@ -1186,22 +1186,38 @@
 Data
-AndBasicPolicy
+ButCertifiedRolesAsInformLevel
 () t
@@ -2893,10 +2893,822 @@
 ());%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void testWithBasicDataButCertifiedRolesAsWarn() throws Exception %7B%0A%09%09DiagnosticData data = TestDiagnosticDataGenerator.generateSimpleDiagnosticData();%0A%09%09%0A%09%09ValidationPolicy policy = TestPolicyGenerator.generatePolicy();%0A%09%09policy.getCertifiedRolesConstraint().setLevel(Level.WARN);%0A%09%09%0A%09%09LevelConstraint failLevel = new LevelConstraint();%0A%09%09failLevel.setLevel(Level.FAIL);%0A%09%09%0A%09%09SignatureAcceptanceValidation validation = new SignatureAcceptanceValidation(data, new Date(), data.getSignatures().get(0), Context.SIGNATURE, policy);%0A%09%09XmlSAV sav = validation.execute();%0A%09%09%0A%09%09for(XmlConstraint constraint : sav.getConstraints()) %7B%0A%09%09%09logger.info(constraint.getName().getValue() + %22 : %22 + constraint.getStatus());%0A%09%09%7D%0A%09%09%0A%09%09Assert.assertEquals(Indication.VALID, sav.getConclusion().getIndication());%0A%09%7D%0A
 %7D%0A

Add test if the level is warning in the SignatureAcceptanceTest