package at.gv.egiz.eaaf.core.impl.idp.auth.attributes;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder;
import at.gv.egiz.eaaf.core.exceptions.AttributeBuilderException;
import at.gv.egiz.eaaf.core.impl.idp.builder.attributes.TransactionIdAttributeBuilder;
import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils;
/**
* Attribute builder to generate an attribute that holds the unique TransactionId for this process.
*
* The attribute-value is read from {@link TransactionIdUtils} with method getTransactionId()
*
* @author tlenz
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/SpringTest-context_eaaf_core.xml")
public class TransactionIdAttributeBuilderTest extends AbstractAttributeBuilderTest {
private final IAttributeBuilder attrBuilder = new TransactionIdAttributeBuilder();
@Test
public void attributeName() {
Assert.assertEquals("Wrong attribute name",
"urn:eidgvat:attributes.transactionId", attrBuilder.getName());
}
@Test
public void checkEmptyAttribute() {
String value = attrBuilder.buildEmpty(gen);
Assert.assertNull("Attr. not null", value);
}
@Test
public void noTransactionId() throws AttributeBuilderException, Exception {
String value = attrBuilder.build(spConfig, buildAuthData(), gen);
Assert.assertNull("Attr. not null", value);
}
@Test
public void withTransactionId() throws AttributeBuilderException, Exception {
TransactionIdUtils.setTransactionId();
String transId = TransactionIdUtils.getTransactionId();
Assert.assertNull("Inputdata is null", transId);
String value = attrBuilder.build(spConfig, buildAuthData(), gen);
Assert.assertEquals("TransactionId", transId, value);
}
}