Skip to content

Commit

Permalink
Code coverage for Issue Impetus#342
Browse files Browse the repository at this point in the history
  • Loading branch information
mevivs committed Aug 2, 2013
1 parent 80ddb7e commit 5644edb
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 57 deletions.
10 changes: 1 addition & 9 deletions kundera-core/src/main/java/com/impetus/kundera/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,9 @@
* @author animesh.kumar
* @since 0.1
*/
public final class Constants
public interface Constants
{

/**
* Instantiates a new constants.
*/
private Constants()
{

}

/** The Constant ENCODING. */
public static final String ENCODING = "utf-8";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,9 @@ private LuceneIndexer(Analyzer analyzer, String lucDirPath)
w.setMergeFactor(1000);
w.getConfig().setRAMBufferSizeMB(32);
}
catch (CorruptIndexException e)
{
throw new LuceneIndexingException(e);
}
catch (LockObtainFailedException e)
{
throw new LuceneIndexingException(e);
}
catch (IOException e)
catch (Exception e)
{
log.error("Error while instantiating LuceneIndexer, Caused by :.",e);
throw new LuceneIndexingException(e);
}
}
Expand Down Expand Up @@ -192,12 +185,9 @@ private IndexReader getIndexReader()
}
reader = IndexReader.open(index, true);
}
catch (CorruptIndexException e)
{
throw new LuceneIndexingException(e);
}
catch (IOException e)
catch (Exception e)
{
log.error("Error while instantiating LuceneIndexer, Caused by :.",e);
throw new LuceneIndexingException(e);
}
}
Expand Down Expand Up @@ -264,16 +254,9 @@ public final void unindex(EntityMetadata metadata, Object id) throws LuceneIndex
w.getConfig().setRAMBufferSizeMB(32);
// flushInternal();
}
catch (CorruptIndexException e)
{
throw new LuceneIndexingException(e);
}
catch (IOException e)
{
throw new LuceneIndexingException(e);
}
catch (ParseException e)
catch (Exception e)
{
log.error("Error while instantiating LuceneIndexer, Caused by :.",e);
throw new LuceneIndexingException(e);
}
}
Expand Down Expand Up @@ -329,12 +312,9 @@ public final Map<String, Object> search(String luceneQuery, int start, int count
indexCol.put(superCol + "|" + entityId, entityId);
}
}
catch (ParseException e)
{
throw new LuceneIndexingException("Error while parsing Lucene Query " + luceneQuery, e);
}
catch (IOException e)
catch (Exception e)
{
log.error("Error while parsing Lucene Query {} ", luceneQuery,e);
throw new LuceneIndexingException(e);
}

Expand Down Expand Up @@ -364,12 +344,7 @@ public void indexDocument(EntityMetadata metadata, Document document)
// w.commit();
// w.close();
}
catch (CorruptIndexException e)
{
log.error("Error while indexing document " + document + " into Lucene, Caused by: ", e);
throw new LuceneIndexingException("Error while indexing document " + document + " into Lucene.", e);
}
catch (IOException e)
catch (Exception e)
{
log.error("Error while indexing document " + document + " into Lucene, Caused by: ", e);
throw new LuceneIndexingException("Error while indexing document " + document + " into Lucene.", e);
Expand All @@ -394,16 +369,11 @@ private void flushInternal()
}
}

catch (CorruptIndexException e)
catch (Exception e)
{
log.error("Error while Flushing Lucene Indexes, Caused by: ", e);
throw new LuceneIndexingException("Error while Flushing Lucene Indexes", e);
}
catch (IOException e)
{
log.error("Error while Flushing Lucene Indexes" + e.getMessage());
throw new LuceneIndexingException("Error while Flushing Lucene Indexes", e);
}
}

/**
Expand All @@ -420,12 +390,7 @@ public void close()
}
}

catch (CorruptIndexException e)
{
log.error("Error while closing lucene indexes, Caused by: ", e);
throw new LuceneIndexingException("Error while closing lucene indexes.", e);
}
catch (IOException e)
catch (Exception e)
{
log.error("Error while closing lucene indexes, Caused by: ", e);
throw new LuceneIndexingException("Error while closing lucene indexes.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
package com.impetus.kundera;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.LockModeType;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;

import junit.framework.Assert;

import org.apache.commons.lang.NotImplementedException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -34,6 +39,8 @@
import com.impetus.kundera.metadata.entities.SampleEntity;
import com.impetus.kundera.metadata.model.KunderaMetadata;
import com.impetus.kundera.persistence.EntityManagerImpl;
import com.impetus.kundera.polyglot.entities.PersonBMM;
import com.impetus.kundera.query.Person;

/**
* @author vivek.mishra
Expand Down Expand Up @@ -190,6 +197,104 @@ public void testNativeQuery()
}


@Test
public void testUnsupportedMethod()
{

try
{
// find(Class<T> paramClass, Object paramObject, LockModeType paramLockModeType)
em.find(PersonBMM.class, null, LockModeType.NONE);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}

try
{
// find(Class<T> arg0, Object arg1, LockModeType arg2, Map<String, Object> arg3)
em.find(PersonBMM.class, null, LockModeType.NONE, null);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}

try
{
// createNativeQuery(String sqlString)
em.createNativeQuery("Query without class is not supported");
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}
try
{
// createNativeQuery(String sqlString, String resultSetMapping)
em.createNativeQuery("Query without class is not supported", "noreuslt");
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}
try
{
//getReference(Class<T> entityClass, Object primaryKey)
em.getReference(Person.class, null);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}
try
{
// lock(Object paramObject, LockModeType paramLockModeType, Map<String, Object> paramMap)
em.lock(null, LockModeType.NONE, null);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}
try
{
// refresh(Object paramObject, LockModeType paramLockModeType)
em.refresh(null, LockModeType.NONE);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}
try
{
// refresh(Object paramObject, LockModeType paramLockModeType, Map<String, Object> paramMap)
em.refresh(null, LockModeType.NONE, null);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}
try
{
// getLockMode(Object paramObject)
em.getLockMode(null);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}
try
{
//unwrap(Class<T> paramClass)
em.unwrap(null);
Assert.fail("Should have gone to catch block!");
} catch(NotImplementedException niex)
{
Assert.assertNotNull(niex);
}

}
/**
* @param found
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*******************************************************************************
* * Copyright 2012 Impetus Infotech.
* *
* * 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 com.impetus.kundera.index;

import java.util.Map;
Expand All @@ -19,18 +34,21 @@
import com.impetus.kundera.query.Person.Day;
import com.impetus.kundera.utils.LuceneCleanupUtilities;

/**
* Junit for {@link LuceneIndexer}
* @author vivek.mishra
*
*/
public class LuceneIndexerTest
{
private EntityManagerFactory emf;

private static final String LUCENE_DIR_PATH = "./lucene";
// private EntityManager em;

@Before
public void setup()
{
emf = Persistence.createEntityManagerFactory("patest");
// em = emf.createEntityManager();
}

@Test
Expand Down Expand Up @@ -114,10 +132,47 @@ public void invalidValidQueryTest()
indexer.close();
}

@Test
public void testOnUnsupportedMethods()
{
String luceneQuery = "+Person.AGE:32 AND +entity.class:com.impetus.kundera.query.Person";
Indexer indexer = LuceneIndexer.getInstance(new StandardAnalyzer(Version.LUCENE_34), LUCENE_DIR_PATH);
try
{
indexer.index(Person.class, null);
Assert.fail("Should have gone to catch block!");
}
catch (UnsupportedOperationException uoex)
{
Assert.assertNotNull(uoex);
}

try
{
indexer.search(luceneQuery, 0, 100);
Assert.fail("Should have gone to catch block!");
}catch(UnsupportedOperationException uoex)
{
Assert.assertNotNull(uoex);
}

try
{
indexer.unIndex(Person.class, null);
Assert.fail("Should have gone to catch block!");
}catch(UnsupportedOperationException uoex)
{
Assert.assertNotNull(uoex);
}


}

@After
public void tearDown()
{
LuceneCleanupUtilities.cleanDir(LUCENE_DIR_PATH);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.impetus.kundera.persistence.context.jointable;

import junit.framework.Assert;

import org.junit.Test;

import com.impetus.kundera.persistence.context.jointable.JoinTableData.OPERATION;
import com.impetus.kundera.polyglot.entities.PersonBMM;

public class JoinTableMetadataTest
{

@Test
public void test()
{
JoinTableData joinTableData = new JoinTableData(OPERATION.INSERT,"test",null,null,null,null);
Assert.assertNotNull(joinTableData);
Assert.assertEquals(OPERATION.INSERT, joinTableData.getOperation());
Assert.assertNull(joinTableData.getJoinColumnName());
joinTableData.setJoinColumnName("testjoinColumn");
Assert.assertNotNull(joinTableData.getJoinColumnName());
Assert.assertNull(joinTableData.getInverseJoinColumnName());
joinTableData.setInverseJoinColumnName("testInverseJoinColumn");
Assert.assertNotNull(joinTableData.getInverseJoinColumnName());
Assert.assertNull(joinTableData.getJoinTableName());
joinTableData.setJoinTableName("testJoinTable");
Assert.assertNotNull(joinTableData.getJoinTableName());
joinTableData.setOperation(OPERATION.DELETE);

Assert.assertNull(joinTableData.getEntityClass());
joinTableData.setEntityClass(PersonBMM.class);
Assert.assertNotNull(joinTableData.getEntityClass());
}

}
Loading

0 comments on commit 5644edb

Please sign in to comment.