/**
 * 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;


/**
 * IndexService contracts test class.
 * Notice: add -javaagent:lib/aspectj1.6/aspectjweaver.jar in VM arguments to use
 * contract4j aspects.
 * @author mhorst
 *
 */
//@Contract
public class IndexContractTest {
	/*
	private final static Logger log = Logger.getLogger(IndexContractTest.class);

	private Mockery context;
	private IIndexService indexService;
	private INotificationHandler notificationHandler;
	
	@Pre(value="source != null", message="source is null!")
	@Post(value="$return.length()>0", message="result size is 0!")
	public String someDummyMethod(String source) {
		System.out.println("got value: "+source);
		return source;
	}

	@Before
	public void init() {
		context = new Mockery();
		indexService = context.mock(IIndexService.class);
		notificationHandler = context.mock(INotificationHandler.class);
	}

//	@Test
	public void testLocalMethod() {
		IndexContractTest test = new IndexContractTest();
		test.someDummyMethod("");
	}

//	@Test
	public void testIndexServiceFacade() {
		ApplicationContext ctx = SpringUtils.getSpringContext(SpringUtils.DEFAULT_JUNIT_RESOURCE);
		IIndexService indexServiceFacade = (IIndexService) ctx.getBean("IndexService");
		indexServiceFacade.identify();
	}
	
//	@Test
	public void testIdentify() {
		// expectations
        context.checking(new Expectations() {{
            allowing(indexService).identify(); 
            will(returnValue(null));
        }});
        log.debug(indexService.getClass().getPackage());
        
		log.debug(indexService.identify()==null?"null":indexService.identify());
		indexService.identify();
		fail("Contract error should be returned!");
	}

//	@Test
	public void testMockNotify() {
		context.checking(new Expectations() {{
            allowing(notificationHandler).notify(null, null, null, null); 
            will(returnValue(false));
        }});
		notificationHandler.notify(null, null, null, null);
		assertFalse(notificationHandler.notify(null, null, null, null));
		fail("Contract error should be returned!");
	}
	
//	@Test
	public void testDummyNotify() {
		notificationHandler = new DummyNotificationHandler();
		notificationHandler.notify(null, null, null, null);
		assertFalse(notificationHandler.notify(null, null, null, null));
//		ContractError is thrown only when Contract specified in DummyNotificationHandler
//		specifying in INotificationHandler seems to be ommited by contract4j
		fail("Contract error should be returned!");
	}
	
	@Test
	public void testDummyIndexService() throws Exception {
		indexService = new DummyIndexService();
		try {
			indexService.getBrowsingStatistics(null, null);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getBrowsingStatistics("query", "ixId");
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		
		try {
			indexService.getIndexStatistics(null);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getIndexStatistics("ixId");
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		
		try {
			indexService.getListOfIndices();
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		
		try {
			indexService.getListOfIndicesCSV();
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		
		try {
			indexService.indexLookup(null, null, null, null);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.indexLookup("", "", "", "");
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		
		try {
			indexService.notify(null, null, null, null);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.notify("", "", "", "");
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		
		try {
			indexService.getBulkData(null, 1, 2);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getBulkData("", 1, 2);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getBulkData("xxx", -1, 2);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getBulkData("xxx", 2, 1);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		indexService.getBulkData("xxx", 1, 1);
		indexService.getBulkData("xxx", 1, 2);
		
		try {
			indexService.getNumberOfResults(null);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getNumberOfResults("");
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			assertTrue(indexService instanceof DummyIndexService);
			ResultsResponse dummyResultResponse = new ResultsResponse();
			dummyResultResponse.setStatus(null);
			dummyResultResponse.setTotal(1);
			((DummyIndexService)indexService).setDummyResultResponse(dummyResultResponse);
			indexService.getNumberOfResults("bd_id");
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			assertTrue(indexService instanceof DummyIndexService);
			ResultsResponse dummyResultResponse = new ResultsResponse();
			dummyResultResponse.setStatus("someStatus");
			dummyResultResponse.setTotal(-1);
			((DummyIndexService)indexService).setDummyResultResponse(dummyResultResponse);
			indexService.getNumberOfResults("bd_id");
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		assertTrue(indexService instanceof DummyIndexService);
		ResultsResponse dummyResultResponse = new ResultsResponse();
		dummyResultResponse.setStatus("someStatus");
		dummyResultResponse.setTotal(0);
		((DummyIndexService)indexService).setDummyResultResponse(dummyResultResponse);
		indexService.getNumberOfResults("bd_id");
		
		try {
			indexService.getSimpleBulkData(null, 1, 2);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getSimpleBulkData("", 1, 2);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getSimpleBulkData("xxx", -1, 2);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		try {
			indexService.getSimpleBulkData("xxx", 2, 1);
			fail("contract error should be thrown!");
		} catch (ContractError error) {
//			expected
			log.debug(error.getMessage());
		}
		indexService.getSimpleBulkData("xxx", 1, 1);
		indexService.getSimpleBulkData("xxx", 1, 2);
	}
	*/
}
