/**
 * Copyright 2008-2009 DRIVER PROJECT (ICM UW)
 * Original author: Marek Horst
 *
 * 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 eu.dnetlib.data.index.ws.nh;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.StringReader;

import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.wsaddressing.W3CEndpointReference;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;

import eu.dnetlib.common.profile.ProfileHeader;
import eu.dnetlib.common.profile.blackboard.Blackboard;
import eu.dnetlib.common.profile.blackboard.BlackboardLastAction;
import eu.dnetlib.common.profile.blackboard.Message;
import eu.dnetlib.common.profile.blackboard.Parameter;
import eu.dnetlib.common.profile.utils.ProfileMarshaller;
import eu.dnetlib.data.index.IndexServiceException;
import eu.dnetlib.data.index.utils.SpringUtils;
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;
import eu.dnetlib.enabling.tools.JaxwsServiceResolverImpl;
import eu.dnetlib.enabling.tools.ServiceResolver;
import eu.dnetlib.miscutils.datetime.DateUtils;


/**
 * Index Notifiction Handler test.
 * @author mhorst
 *
 */
public class IndexNotificationHandlerTest {

	ApplicationContext context;
	IndexNotificationHandler notificationHandler;
	
	@Before
	public void setUp() throws Exception {
		context = SpringUtils.getSpringContext(SpringUtils.DEFAULT_JUNIT_RESOURCE);
		notificationHandler = (IndexNotificationHandler) context.getBean("IndexNotificationHandler");
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testNotify() {
		assertNotNull(notificationHandler);
		
		ProfileHeader profileHeader = null;
		Blackboard blackboard = null;
		
		String subscrId = IndexNotificationHandler.SUBSCR_ID_UNSPECIFIED;
		String topic = "someTopic";
		String isId	= "someIsId";
		
//		null message
		String message = null;
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		message content without header and blackboard parts
		message = ProfileMarshaller.generateBBProfile(null, null);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		message content without blackboard part
		profileHeader = new ProfileHeader("someResourceIdentifier",
				"unsupportedType","unsupportedKind");
		message = ProfileMarshaller.generateBBProfile(profileHeader, null);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		message content with unsupported serviceType
		blackboard = new Blackboard();
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		empty blackboard content
		profileHeader = new ProfileHeader("someResourceIdentifier",
				ProfileHeader.INDEX_SERVICE_TYPE,"anyKind");
		blackboard = new Blackboard();
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		no message inside blackboard specified
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate","someValue"));
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		neither action nor action status specified
		String predefinedId = "predefinedId";
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		Message bbMessage = new Message();
		bbMessage.setId(predefinedId);
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		no action specified
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		unsupported action specified
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.HALT);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		valid action, not all params provided
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.CREATE);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		valid action with all params, MDFormat profile not available for layout1 layout
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.CREATE);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_FORMAT,"DMF"));
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_LAYOUT,"layout1"));
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertFalse(notificationHandler.notify(subscrId, topic, isId, message));
		
//		valid action with all params, MDFormat profile registered in IS-Store;
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.CREATE);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_FORMAT,"DMF"));
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_LAYOUT,"index"));
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertTrue(notificationHandler.notify(subscrId, topic, isId, message));
		
	}

	public void testNotifyCreateIndex() throws IndexServiceException {
		fail("Reimplement test after recent changes, use mock services");
		/*
		ProfileHeader profileHeader = null;
		Blackboard blackboard = null;
		Message bbMessage = null;
		String message = null;
		
		String subscrId = IndexNotificationHandler.SUBSCR_ID_UNSPECIFIED;
		String topic = "someTopic";
		String isId	= "someIsId";
		String predefinedId = "predefinedId";
		
		profileHeader = new ProfileHeader("someResourceIdentifier",
				ProfileHeader.INDEX_SERVICE_TYPE,"anyKind");
		
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.CREATE);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		String predefinedFormat = "DMF";
		String predefinedLayout = "layout1";
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_FORMAT,predefinedFormat));
		List<FieldSpec> fieldSpecList = new ArrayList<FieldSpec>();
		fieldSpecList.add(new FieldSpec("a"));
		fieldSpecList.add(new FieldSpec("b"));
		fieldSpecList.add(new FieldSpec("c"));
		Map<String,List<FieldSpec>> data = new HashMap<String, List<FieldSpec>>();
		data.put(predefinedLayout, fieldSpecList);
		notificationHandler.getMdFormatContainer().storeOrUpdateData(predefinedFormat, data);
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_LAYOUT, predefinedLayout));
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertTrue(notificationHandler.notify(subscrId, topic, isId, message));
		
//		checking IS profile
		MockDataContainer dataContainer = (MockDataContainer) context.getBean("MockDataContainer");
		assertNotNull(dataContainer);
		Set<String> profilesIds = dataContainer.getAllProfilesIds();
		assertNotNull(profilesIds);
		assertEquals(1, profilesIds.size());
		Iterator<String> it = profilesIds.iterator();
		String createdIxId = it.next();
		String createdIndexProfile = dataContainer.getResourceProfile(createdIxId);
		assertNotNull(createdIndexProfile);
		System.out.println(createdIndexProfile);
		
//		checking received create event
		SearchModuleFacade searchModuleFacade = (SearchModuleFacade) context.getBean("internalSearchModule");
		if (!(searchModuleFacade instanceof SearchModuleMock)) {
			fail("Couldn't perform notification validation. Listener is not a SampleEventListener instance.");
		} else {
			SearchModuleMock mockSearchModule = (SearchModuleMock) searchModuleFacade;
			SampleEventListener sampleListener = mockSearchModule.getSampleEventListener();
			assertNotNull(sampleListener);
			assertEquals(1, sampleListener.getReceivedEvents().size());
			assertTrue(sampleListener.getReceivedEvents().get(0) instanceof CreateIndexEvent);
			CreateIndexEvent receivedEvent = (CreateIndexEvent) sampleListener.getReceivedEvents().get(0);
			assertNotNull(receivedEvent);
			assertEquals(createdIxId, receivedEvent.getIndexId());
			assertEquals(predefinedFormat, receivedEvent.getFormat());
			assertEquals(predefinedLayout, receivedEvent.getLayout());
			List<FieldSpec> retrievedFieldSpecs = notificationHandler.
				getMdFormatContainer().getFieldsSpecification(predefinedFormat, predefinedLayout);
			assertNotNull(retrievedFieldSpecs);
			assertEquals(3, retrievedFieldSpecs.size());
		}
		*/
	}
	
	public void testNotifyDeleteIndex() {
		fail("Reimplement test after recent changes, use mock services");
		/*
		ProfileHeader profileHeader = null;
		Blackboard blackboard = null;
		Message bbMessage = null;
		String message = null;
		
		String subscrId = IndexNotificationHandler.SUBSCR_ID_UNSPECIFIED;
		String topic = "someTopic";
		String isId	= "someIsId";
		String predefinedId = "predefinedId";
		
		profileHeader = new ProfileHeader("someResourceIdentifier",
				ProfileHeader.INDEX_SERVICE_TYPE,"anyKind");
		
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.CREATE);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		String predefinedFormat = "DMF";
		String predefinedLayout = "layout1";
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_FORMAT,predefinedFormat));
		List<FieldSpec> fieldSpecList = new ArrayList<FieldSpec>();
		fieldSpecList.add(new FieldSpec("a"));
		fieldSpecList.add(new FieldSpec("b"));
		fieldSpecList.add(new FieldSpec("c"));
		Map<String,List<FieldSpec>> data = new HashMap<String, List<FieldSpec>>();
		data.put(predefinedLayout, fieldSpecList);
		notificationHandler.getMdFormatContainer().storeOrUpdateData(predefinedFormat, data);
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_LAYOUT, predefinedLayout));
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertTrue(notificationHandler.notify(subscrId, topic, isId, message));
		
//		checking IS profile
		MockDataContainer dataContainer = (MockDataContainer) context.getBean("MockDataContainer");
		assertNotNull(dataContainer);
		Set<String> profilesIds = dataContainer.getAllProfilesIds();
		assertNotNull(profilesIds);
		assertEquals(1, profilesIds.size());
		Iterator<String> it = profilesIds.iterator();
		String createdIxId = it.next();
		String createdIndexProfile = dataContainer.getResourceProfile(createdIxId);
		assertNotNull(createdIndexProfile);
		
//		sending delete notification
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.DELETE);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_ID,createdIxId));
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertTrue(notificationHandler.notify(subscrId, topic, isId, message));
		
//		checking IS profile
		dataContainer = (MockDataContainer) context.getBean("MockDataContainer");
		assertNotNull(dataContainer);
		profilesIds = dataContainer.getAllProfilesIds();
		assertNotNull(profilesIds);
		assertEquals(0, profilesIds.size());
		
//		checking received delete event
		SearchModuleFacade searchModuleFacade = (SearchModuleFacade) context.getBean("internalSearchModule");
		if (!(searchModuleFacade instanceof SearchModuleMock)) {
			fail("Couldn't perform notification validation. Listener is not a SampleEventListener instance.");
		} else {
			SearchModuleMock mockSearchModule = (SearchModuleMock) searchModuleFacade;
			SampleEventListener sampleListener = mockSearchModule.getSampleEventListener();
			assertNotNull(sampleListener);
			assertEquals(2, sampleListener.getReceivedEvents().size());
			assertTrue(sampleListener.getReceivedEvents().get(0) instanceof CreateIndexEvent);
			assertTrue(sampleListener.getReceivedEvents().get(1) instanceof DeleteIndexEvent);
			DeleteIndexEvent receivedEvent = (DeleteIndexEvent) sampleListener.getReceivedEvents().get(1);
			assertNotNull(receivedEvent);
			assertEquals(createdIxId, receivedEvent.getIndexId());
		}
		*/
	}
	
	public void testNotifyFeedIndex() {
		fail("Reimplement test after recent changes, use mock services");
		/*
		ProfileHeader profileHeader = null;
		Blackboard blackboard = null;
		Message bbMessage = null;
		String message = null;
		
		String subscrId = IndexNotificationHandler.SUBSCR_ID_UNSPECIFIED;
		String topic = "someTopic";
		String isId	= "someIsId";
		String predefinedId = "predefinedId";
		
		profileHeader = new ProfileHeader("someResourceIdentifier",
				ProfileHeader.INDEX_SERVICE_TYPE,"anyKind");
		
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.CREATE);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		String predefinedFormat = "DMF";
		String predefinedLayout = "layout1";
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_FORMAT,predefinedFormat));
		List<FieldSpec> fieldSpecList = new ArrayList<FieldSpec>();
		fieldSpecList.add(new FieldSpec("a"));
		fieldSpecList.add(new FieldSpec("b"));
		fieldSpecList.add(new FieldSpec("c"));
		Map<String,List<FieldSpec>> data = new HashMap<String, List<FieldSpec>>();
		data.put(predefinedLayout, fieldSpecList);
		notificationHandler.getMdFormatContainer().storeOrUpdateData(predefinedFormat, data);
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_LAYOUT, predefinedLayout));
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertTrue(notificationHandler.notify(subscrId, topic, isId, message));
		
//		checking IS profile
		MockDataContainer dataContainer = (MockDataContainer) context.getBean("MockDataContainer");
		assertNotNull(dataContainer);
		Set<String> profilesIds = dataContainer.getAllProfilesIds();
		assertNotNull(profilesIds);
		assertEquals(1, profilesIds.size());
		Iterator<String> it = profilesIds.iterator();
		String createdIxId = it.next();
		String createdIndexProfile = dataContainer.getResourceProfile(createdIxId);
		assertNotNull(createdIndexProfile);
		
//		sending feed notification
		blackboard = new Blackboard();
		blackboard.setLastRequest(new BlackboardLastAction("someDate",predefinedId));
		bbMessage = new Message();
		bbMessage.setId(predefinedId);
		bbMessage.setAction(Message.Action.FEED);
		bbMessage.setActionStatus(Message.ActionStatus.ASSIGNED);
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_ID,createdIxId));
		String predefinedResultSetEPR = "predefinedResultSetEPR";
		BASE64Encoder encoder = new BASE64Encoder();
		String predefinedResultSetEPRBase64Enc = encoder.encode(predefinedResultSetEPR.getBytes());
		String predefinedType = "predefinedType";
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_FEEDING_TYPE,predefinedType));
		bbMessage.addParam(new Parameter(Parameter.PARAM_NAME_RESULTSET_EPR,predefinedResultSetEPRBase64Enc));
		blackboard.addMessage(bbMessage);
		message = ProfileMarshaller.generateBBProfile(profileHeader, blackboard);
		assertTrue(notificationHandler.notify(subscrId, topic, isId, message));
		
//		checking received delete event
		SearchModuleFacade searchModuleFacade = (SearchModuleFacade) context.getBean("internalSearchModule");
		if (!(searchModuleFacade instanceof SearchModuleMock)) {
			fail("Couldn't perform notification validation. Listener is not a SampleEventListener instance.");
		} else {
			SearchModuleMock mockSearchModule = (SearchModuleMock) searchModuleFacade;
			SampleEventListener sampleListener = mockSearchModule.getSampleEventListener();
			assertNotNull(sampleListener);
			assertEquals(2, sampleListener.getReceivedEvents().size());
			assertTrue(sampleListener.getReceivedEvents().get(0) instanceof CreateIndexEvent);
			assertTrue(sampleListener.getReceivedEvents().get(1) instanceof FeedIndexEvent);
			FeedIndexEvent receivedEvent = (FeedIndexEvent) sampleListener.getReceivedEvents().get(1);
			assertNotNull(receivedEvent);
			assertEquals(createdIxId, receivedEvent.getIndexId());
			assertEquals(predefinedType, receivedEvent.getType());
			assertNotNull(receivedEvent.getFeedIterator());
			assertTrue(receivedEvent.getFeedIterator() instanceof ResultSetFeedIterator);
			ResultSetFeedIterator rsFeedIterator = (ResultSetFeedIterator) receivedEvent.getFeedIterator();
			assertEquals(predefinedResultSetEPR, rsFeedIterator.getResultSetEPR());
		}
		*/
	}
	
	@Test
	public void testDateFormat() {
		DateUtils dateu = new DateUtils();
		System.out.println(dateu.getDateAsISO8601String());
	}
	
	@Test
	public void testDecode() {
		String resultSetEPRBase64Enc = 
			"PEVuZHBvaW50UmVmZXJlbmNlIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDA1LzA4L2FkZHJlc"+
			"3NpbmciPjxBZGRyZXNzPmh0dHA6Ly9ub2RlMS5pbnRlZ3JhdGlvbi5kcml2ZXIucmVzZWFyY2gtaW"+
			"5mcmFzdHJ1Y3R1cmVzLmV1OjgwOTAvYXBwL3NlcnZpY2VzL3Jlc3VsdFNldDwvQWRkcmVzcz48UmV"+
			"mZXJlbmNlUGFyYW1ldGVycz48UmVzb3VyY2VJZGVudGlmaWVyOlJlc291cmNlSWRlbnRpZmllciB4"+
			"bWxucz0iaHR0cDovL3d3dy5kcml2ZXIub3JnIiB4bWxuczp3c2E9Imh0dHA6Ly93d3cudzMub3JnL"+
			"zIwMDUvMDgvYWRkcmVzc2luZyIgeG1sbnM6UmVzb3VyY2VJZGVudGlmaWVyPSJodHRwOi8vd3d3Lm"+
			"RyaXZlci5vcmciPnJzLWZiN2ZjMGVkLWVhMDItNDI2Yy04NWE5LTdiYjU0MTE5MDExMzwvUmVzb3V"+
			"yY2VJZGVudGlmaWVyOlJlc291cmNlSWRlbnRpZmllcj48L1JlZmVyZW5jZVBhcmFtZXRlcnM+PE1l"+
			"dGFkYXRhPjx3c2F3OkludGVyZmFjZU5hbWUgeG1sbnM6bnMxPSJodHRwOi8vcm1pLnJlc3VsdHNld"+
			"C5lbmFibGluZy5kbmV0bGliLmV1LyIgeG1sbnM6d3NhPSJodHRwOi8vd3d3LnczLm9yZy8yMDA1Lz"+
			"A4L2FkZHJlc3NpbmciIHhtbG5zOndzYXc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDYvMDUvYWRkcmV"+
			"zc2luZy93c2RsIj5uczE6UmVzdWx0U2V0U2VydmljZTwvd3NhdzpJbnRlcmZhY2VOYW1lPjx3c2F3"+
			"OlNlcnZpY2VOYW1lIEVuZHBvaW50TmFtZT0iUmVzdWx0U2V0U2VydmljZVBvcnQiIHhtbG5zPSIiI"+
			"HhtbG5zOm5zMj0iaHR0cDovL3JtaS5yZXN1bHRzZXQuZW5hYmxpbmcuZG5ldGxpYi5ldS8iIHhtbG"+
			"5zOndzYT0iaHR0cDovL3d3dy53My5vcmcvMjAwNS8wOC9hZGRyZXNzaW5nIiB4bWxuczp3c2F3PSJ"+
			"odHRwOi8vd3d3LnczLm9yZy8yMDA2LzA1L2FkZHJlc3Npbmcvd3NkbCIgeG1sbnM6bnM1PSJodHRw"+
			"Oi8vd3d3LnczLm9yZy8yMDA1LzA4L2FkZHJlc3NpbmciPm5zMjpSZXN1bHRTZXRTZXJ2aWNlU2Vyd"+
			"mljZTwvd3NhdzpTZXJ2aWNlTmFtZT48d3NkbDpkZWZpbml0aW9ucyB4bWxuczp3c2E9Imh0dHA6Ly"+
			"93d3cudzMub3JnLzIwMDUvMDgvYWRkcmVzc2luZyIgeG1sbnM6d3Nhdz0iaHR0cDovL3d3dy53My5"+
			"vcmcvMjAwNi8wNS9hZGRyZXNzaW5nL3dzZGwiIHhtbG5zOndzZGw9Imh0dHA6Ly9zY2hlbWFzLnht"+
			"bHNvYXAub3JnL3dzZGwvIj48d3NkbDppbXBvcnQgbG9jYXRpb249Imh0dHA6Ly9ub2RlMS5pbnRlZ"+
			"3JhdGlvbi5kcml2ZXIucmVzZWFyY2gtaW5mcmFzdHJ1Y3R1cmVzLmV1OjgwOTAvYXBwL3NlcnZpY2"+
			"VzL3Jlc3VsdFNldD93c2RsIiBuYW1lc3BhY2U9Imh0dHA6Ly9ybWkucmVzdWx0c2V0LmVuYWJsaW5"+
			"nLmRuZXRsaWIuZXUvIiB4bWxucz0iIiB4bWxuczpuczU9Imh0dHA6Ly93d3cudzMub3JnLzIwMDUv"+
			"MDgvYWRkcmVzc2luZyIvPjwvd3NkbDpkZWZpbml0aW9ucz48aW5mcmFzdHJ1Y3R1cmU6aW5mcmFzd"+
			"HJ1Y3R1cmUgeG1sbnM9Imh0dHA6Ly9kbmV0bGliLmV1L2VuZHBvaW50UmVmZXJlbmNlIiB4bWxucz"+
			"p3c2E9Imh0dHA6Ly93d3cudzMub3JnLzIwMDUvMDgvYWRkcmVzc2luZyIgeG1sbnM6d3Nhdz0iaHR"+
			"0cDovL3d3dy53My5vcmcvMjAwNi8wNS9hZGRyZXNzaW5nL3dzZGwiIHhtbG5zOmluZnJhc3RydWN0"+
			"dXJlPSJodHRwOi8vZG5ldGxpYi5ldS9lbmRwb2ludFJlZmVyZW5jZSI+ZGV2ZWxvcG1lbnQ8L2luZ"+
			"nJhc3RydWN0dXJlOmluZnJhc3RydWN0dXJlPjwvTWV0YWRhdGE+PC9FbmRwb2ludFJlZmVyZW5jZT"+
			"4=";

		String resultSetEPR = IndexNotificationHandler.decode(resultSetEPRBase64Enc);
		assertNotNull(resultSetEPR);
		System.out.println(resultSetEPR);
		W3CEndpointReference epr = (W3CEndpointReference) 
	 	W3CEndpointReference.readFrom
	 		(new StreamSource(new StringReader(resultSetEPR)));
	 
		final ServiceResolver serviceResolver = new JaxwsServiceResolverImpl();
		final ResultSetService resultSetService = 
			serviceResolver.getService(ResultSetService.class, epr);
		final String rsId = serviceResolver.getResourceIdentifier(epr);
		
		assertNotNull(resultSetService);
		assertNotNull(rsId);
		System.out.println(resultSetService);
		System.out.println(rsId);
	}
}
