Search in sources :

Example 1 with PeppolIdentifierFactory

use of com.helger.peppolid.factory.PeppolIdentifierFactory in project phoss-directory by phax.

the class IndexerResourceTest method testCreateAndDeleteParticipant.

@Test
public void testCreateAndDeleteParticipant() throws IOException {
    final AtomicInteger aIndex = new AtomicInteger(0);
    final PeppolIdentifierFactory aIF = PeppolIdentifierFactory.INSTANCE;
    // Create
    final int nCount = 4;
    CommonsTestHelper.testInParallel(nCount, () -> {
        final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + aIndex.getAndIncrement());
        final String sPayload = aPI.getURIPercentEncoded();
        LOGGER.info("PUT " + sPayload);
        final String sResponseMsg = m_aTarget.path("1.0").request().put(Entity.text(sPayload), String.class);
        assertEquals("", sResponseMsg);
    });
    LOGGER.info("waiting");
    ThreadHelper.sleep(2000);
    for (int i = 0; i < nCount; ++i) {
        final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + i);
        assertTrue(PDMetaManager.getStorageMgr().containsEntry(aPI, EQueryMode.ALL));
    }
    // Delete
    aIndex.set(0);
    CommonsTestHelper.testInParallel(nCount, () -> {
        final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + aIndex.getAndIncrement());
        final String sPI = aPI.getURIEncoded();
        LOGGER.info("DELETE " + sPI);
        final String sResponseMsg = m_aTarget.path("1.0").path(sPI).request().delete(String.class);
        assertEquals("", sResponseMsg);
    });
    LOGGER.info("waiting");
    ThreadHelper.sleep(2000);
    for (int i = 0; i < nCount; ++i) {
        final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + i);
        assertFalse(PDMetaManager.getStorageMgr().containsEntry(aPI, EQueryMode.ALL));
    }
    // Test with invalid URL encoded ID
    {
        final String sPayload = "iso6523-actorid-upis%3a%3a9915%3atest0%%%abc";
        LOGGER.info("CREATE " + sPayload);
        try {
            m_aTarget.path("1.0").request().put(Entity.text(sPayload), String.class);
            fail();
        } catch (final BadRequestException ex) {
        // Expected
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BadRequestException(javax.ws.rs.BadRequestException) PeppolIdentifierFactory(com.helger.peppolid.factory.PeppolIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Aggregations

IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 PeppolIdentifierFactory (com.helger.peppolid.factory.PeppolIdentifierFactory)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BadRequestException (javax.ws.rs.BadRequestException)1 Test (org.junit.Test)1