forked from Impetus/kundera
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commented out jacoco plugin
- Loading branch information
Showing
13 changed files
with
274 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
kundera-core/src/test/java/com/impetus/kundera/query/CoreQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* Copyright 2013 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.query; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import com.impetus.kundera.client.Client; | ||
import com.impetus.kundera.metadata.model.EntityMetadata; | ||
import com.impetus.kundera.persistence.EntityReader; | ||
import com.impetus.kundera.persistence.PersistenceDelegator; | ||
import com.impetus.kundera.query.QueryImpl; | ||
import com.impetus.kundera.query.KunderaQuery.FilterClause; | ||
|
||
/** | ||
* @author vivek.mishra | ||
* Test implementation for {@link Query} interface. | ||
* | ||
*/ | ||
public class CoreQuery<E> extends QueryImpl<E> | ||
{ | ||
|
||
public CoreQuery(String query, final KunderaQuery kunderaQuery, PersistenceDelegator persistenceDelegator) | ||
{ | ||
super(query, persistenceDelegator); | ||
this.kunderaQuery = kunderaQuery; | ||
} | ||
|
||
|
||
public List getResutList() | ||
{ | ||
return super.getResultList(); | ||
} | ||
|
||
@Override | ||
protected List<Object> populateEntities(EntityMetadata m, Client client) | ||
{ | ||
// Only find by id queries supported. | ||
|
||
EntityMetadata entityMetadata = getEntityMetadata(); | ||
Object value = null; | ||
for(Object clause: getKunderaQuery().getFilterClauseQueue()) | ||
{ | ||
if(clause instanceof FilterClause) | ||
{ | ||
String property = ((FilterClause)clause).getProperty(); | ||
String condition = ((FilterClause)clause).getCondition(); | ||
value = ((FilterClause)clause).getValue(); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
Object result = client.find(m.getEntityClazz(), value); | ||
List results = new ArrayList(); | ||
if(result != null) | ||
{ | ||
results.add(result); | ||
} | ||
return results; | ||
} | ||
|
||
@Override | ||
protected List<Object> recursivelyPopulateEntities(EntityMetadata m, Client client) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
protected EntityReader getReader() | ||
{ | ||
return new CoreTestEntityReader(); | ||
} | ||
|
||
@Override | ||
protected int onExecuteUpdate() | ||
{ | ||
return getResultList().size(); | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
// Do nothing. | ||
|
||
} | ||
|
||
@Override | ||
public Iterator<E> iterate() | ||
{ | ||
return null; | ||
} | ||
|
||
} |
126 changes: 126 additions & 0 deletions
126
kundera-core/src/test/java/com/impetus/kundera/query/QueryImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* Copyright 2013 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.query; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.Persistence; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.impetus.kundera.CoreTestUtilities; | ||
import com.impetus.kundera.client.DummyDatabase; | ||
import com.impetus.kundera.metadata.model.KunderaMetadata; | ||
import com.impetus.kundera.persistence.PersistenceDelegator; | ||
import com.impetus.kundera.query.Person.Day; | ||
|
||
/** | ||
* @author vivek.mishra | ||
* junit for {@link QueryImpl} | ||
* | ||
*/ | ||
public class QueryImplTest | ||
{ | ||
|
||
private static final String PU = "patest"; | ||
|
||
private EntityManagerFactory emf; | ||
|
||
private EntityManager em; | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@Before | ||
public void setUp() throws Exception | ||
{ | ||
KunderaMetadata.INSTANCE.setApplicationMetadata(null); | ||
emf = Persistence.createEntityManagerFactory(PU); | ||
em = emf.createEntityManager(); | ||
|
||
} | ||
|
||
@Test | ||
public void test() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException | ||
{ | ||
Person p1 = new Person(); | ||
p1.setAge(98); | ||
p1.setPersonId("1"); | ||
p1.setDay(Day.SATURDAY); | ||
|
||
em.persist(p1); | ||
|
||
em.clear(); | ||
|
||
Person p2 = new Person(); | ||
p2.setAge(100); | ||
p2.setPersonId("2"); | ||
p2.setDay(Day.SATURDAY); | ||
|
||
em.persist(p2); | ||
|
||
final String query = "Select p from Person p where p.personId = '1'"; | ||
|
||
PersistenceDelegator delegator = CoreTestUtilities.getDelegator(em); | ||
|
||
KunderaQueryParser queryParser; | ||
KunderaQuery kunderaQuery = parseQuery(query); | ||
|
||
CoreQuery queryObj = new CoreQuery(query, kunderaQuery, delegator); | ||
|
||
List<Person> results = queryObj.getResultList(); | ||
|
||
Assert.assertEquals(1,results.size()); | ||
|
||
|
||
final String deleteQuery = "Delete from Person p where p.personId = '1'"; | ||
|
||
kunderaQuery = parseQuery(deleteQuery); | ||
queryObj = new CoreQuery(query, kunderaQuery, delegator); | ||
|
||
queryObj.executeUpdate(); | ||
|
||
|
||
kunderaQuery = parseQuery(query); | ||
queryObj = new CoreQuery(query, kunderaQuery, delegator); | ||
|
||
results = queryObj.getResultList(); | ||
|
||
Assert.assertEquals(0,results.size()); | ||
} | ||
|
||
private KunderaQuery parseQuery(final String query) | ||
{ | ||
KunderaQuery kunderaQuery = new KunderaQuery(); | ||
KunderaQueryParser queryParser = new KunderaQueryParser(kunderaQuery, query); | ||
queryParser.parse(); | ||
kunderaQuery.postParsingInit(); | ||
return kunderaQuery; | ||
} | ||
|
||
|
||
@After | ||
public void tearDown() | ||
{ | ||
DummyDatabase.INSTANCE.dropDatabase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.