Tuesday, 31 August 2021

Junit5: @IncludePackages: specify the packages for test suite

@IncludePackages specifies the packages to be included when running a test suite on the JUnit Platform.

 


For example, below snippet runs all the test cases in the package "com.sample.app.dummy" and its subpackages.

@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectPackages({"com.sample.app.dummy"})
public class IncludePackagesDemo {

}


What if you want to selectively run the packages?

You can use @IncludePackages and @ExcludePackages to explicitly include and exclude the packages.

 

Example

@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectPackages({"com.sample.app.dummy"})
@IncludePackages({"com.sample.app.dummy.dummy1"})
public class IncludePackagesDemo {

}


Above snippet execute below test classes.

 

a.   Dummy1D1Test

b.   Dummy1D2Test

c.    Dummy1Test

 

Find the below working application.

 

DummyTest.java

package com.sample.app.dummy;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class DummyTest {

    @Test
    public void test1() {
        assertTrue(true);
    }
}


Dummy1Test.java

package com.sample.app.dummy.dummy1;

import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.Test;

public class Dummy1Test {
    @Test
    public void test1() {
        assertTrue(true);
    }
}


Dummy1D1Test.java

package com.sample.app.dummy.dummy1.d1;

import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.Test;

public class Dummy1D1Test {

    @Test
    public void test1() {
        assertTrue(true);
    }

}


Dummy1D2Test.java

package com.sample.app.dummy.dummy1.d2;

import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.Test;

public class Dummy1D2Test {
    @Test
    public void test1() {
        assertTrue(true);
    }
}


Dummy2D1Test.java

package com.sample.app.dummy.dummy2.d1;

import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.Test;

public class Dummy2D1Test {
    @Test
    public void test1() {
        assertTrue(true);
    }
}


IncludePackagesDemo.java

package com.sample.app.suite;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.IncludePackages;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.SuiteDisplayName;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectPackages({"com.sample.app.dummy"})
@IncludePackages({"com.sample.app.dummy.dummy1"})
public class IncludePackagesDemo {

}


Run ‘IncludePackagesDemo’ class, you will see the executed test methods result in junit report window.





Note

By default, @SelectPackages will only include test classes whose names either begin with Test or end with Test or Tests.



Previous                                                    Next                                                    Home

Neo4j: NOT operator

The NOT operator extract items if the condition(s) is NOT TRUE.

 

For example, below query return all the persons whose city is not Bangalore and designation is not Employee

MATCH(n:Person) WHERE NOT (n.city="Bangalore" OR n.designation="Employee") RETURN n

 

Let’s see the same with an example.

 

Step 1: Open neo4j browser by hitting following url in browser.

http://localhost:7474/browser/

 


 

Step 2: Insert data by executing below query.

CREATE (p1:Person{name: "Rama Krishna", age: 32, city: "Bangalore", male: true, designation: "CEO"}),
(p2:Person{name: "Murali", age: 32, city: "Hyderabad", male: true, designation: "Vice President"}),
(p3:Person{name: "Gopi", age: 34, city: "Chennai", male: true, designation: "Vice President"}),
(p4:Person{name: "Kiran", age: 28, city: "Bangalore", male: true, designation: "Director"}),
(p5:Person{name: "Siva", age: 45, city: "Hyderabad", male: true, designation: "Director"}),
(p6:Person{name: "Kiran", age: 36, city: "Hyderabad", male: true, designation: "Manager"}),
(p7:Person{name: "Ritweek", age: 23, city: "Bangalore", male: true, designation: "Manager"}),
(p8:Person{name: "Sudheer", age: 24, city: "Chennai", male: true, designation: "Manager"}),
(p9:Person{name: "Naveen", age: 37, city: "Bangalore", male: true, designation: "Employee"}),
(p10:Person{name: "Sailaja", age: 31, city: "Hyderabad", female: true, designation: "Employee"}),
(p11:Person{name: "Harika", age: 36, city: "Bangalore", female: true, designation: "Employee"}),
(p12:Person{name: "Brahmam", age: 41, city: "Bangalore", male: true, designation: "Employee"}),
(office1:Location{name: "Pluto", city: "Bangalore"}),
(office2:Location{name: "Mars", city: "Chennai"})
MERGE (p2)-[:REPORT_TO{from: 2014, description: "reports to"}]->(p1)
MERGE (p3)-[:REPORT_TO{from: 2016, description: "reports to"}]->(p1)
MERGE (p4)-[:REPORT_TO{from: 1997, description: "reports to"}]->(p2)
MERGE (p5)-[:REPORT_TO{from: 1997, description: "reports to"}]->(p3)
MERGE (p6)-[:REPORT_TO{from: 2001, description: "reports to"}]->(p4)
MERGE (p7)-[:REPORT_TO{from: 2009, description: "reports to"}]->(p4)
MERGE (p8)-[:REPORT_TO{from: 1998, description: "reports to"}]->(p5)
MERGE (p9)-[:REPORT_TO{from: 2003, description: "reports to"}]->(p6)
MERGE (p10)-[:REPORT_TO{from: 2004, description: "reports to"}]->(p6)
MERGE (p11)-[:REPORT_TO{from: 2008, description: "reports to"}]->(p7)
MERGE (p12)-[:REPORT_TO{from: 2019, description: "reports to"}]->(p8)
MERGE (p2)-[:FRIEND_TO{from: 2014, description: "friend to"}]->(p1)
MERGE (p10)-[:FRIEND_TO{from: 2014, description: "friend to"}]->(p8)
MERGE (p7)-[:FRIEND_TO{from: 2014, description: "friend to"}]->(p9)
MERGE (p3)-[:RELATIVE_TO{from: 2014, description: "relative to"}]->(p4)
RETURN p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, office1, office2

 


Get all the persons whose city is not Bangalore and designation is not Employee

MATCH(n:Person) WHERE NOT (n.city="Bangalore" OR n.designation="Employee") RETURN n

 



Get all the persons whose age is not 32, 45, 38.

MATCH(n:Person) WHERE n.age NOT IN [32, 45, 38]

RETURN n


 


 

Previous                                                    Next                                                    Home

ArangoDB: Update the documents by example

‘collection.updateByExample()’ method is used to update all the matched documents with new content. It will not replace entire document, it just updated the matched values in the document.

 

Signature

collection.updateByExample(example, newValue)

collection.updateByExample(document, newValue, keepNull, waitForSync, limit)

collection.updateByExample(document, newValue, options)

 

Attributes with null values are stored in the database by default. If 'keepNull' is set to false, then all the attributes in data with null values will be removed from the target document.

 

if ‘waitForSync’ parameter is set to true, then it forces the synchronization of replaceByExample operation to disk. . If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behaviour is applied.

 

‘limit’ parameter is used to restrict the number of documents to be affected with this operation.

 

Let’s experiment it with an example.

127.0.0.1:8529@abc_org> db.test.toArray()
[ 
  { 
    "_key" : "33825", 
    "_id" : "test/33825", 
    "_rev" : "_cS-_Uj----", 
    "a" : 1, 
    "b" : 1, 
    "c" : 1 
  }, 
  { 
    "_key" : "33827", 
    "_id" : "test/33827", 
    "_rev" : "_cS-_YP----", 
    "a" : 1, 
    "b" : 0, 
    "c" : 1 
  }, 
  { 
    "_key" : "33835", 
    "_id" : "test/33835", 
    "_rev" : "_cS-_bQ2---", 
    "a" : 1, 
    "b" : 0, 
    "c" : 0 
  }, 
  { 
    "_key" : "33837", 
    "_id" : "test/33837", 
    "_rev" : "_cS-CmaK---", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  }, 
  { 
    "_key" : "33845", 
    "_id" : "test/33845", 
    "_rev" : "_cS-CmaK--A", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  }, 
  { 
    "_key" : "33847", 
    "_id" : "test/33847", 
    "_rev" : "_cS-CmaO---", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  }, 
  { 
    "_key" : "33849", 
    "_id" : "test/33849", 
    "_rev" : "_cS-CmaO--A", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  } 
]

 

If a document contain {"x" : 1}, then update it with {"x" : 0, "b": 1}

 

127.0.0.1:8529@abc_org> db.test.updateByExample({"x" : 1}, {"x" : 0, "b": 1})

4

127.0.0.1:8529@abc_org> db.test.toArray()
[ 
  { 
    "_key" : "33825", 
    "_id" : "test/33825", 
    "_rev" : "_cS-_Uj----", 
    "a" : 1, 
    "b" : 1, 
    "c" : 1 
  }, 
  { 
    "_key" : "33827", 
    "_id" : "test/33827", 
    "_rev" : "_cS-_YP----", 
    "a" : 1, 
    "b" : 0, 
    "c" : 1 
  }, 
  { 
    "_key" : "33835", 
    "_id" : "test/33835", 
    "_rev" : "_cS-_bQ2---", 
    "a" : 1, 
    "b" : 0, 
    "c" : 0 
  }, 
  { 
    "_key" : "33837", 
    "_id" : "test/33837", 
    "_rev" : "_cS-WEUm---", 
    "a" : 1, 
    "x" : 0, 
    "y" : 1, 
    "b" : 1 
  }, 
  { 
    "_key" : "33845", 
    "_id" : "test/33845", 
    "_rev" : "_cS-WEUm--A", 
    "a" : 1, 
    "x" : 0, 
    "y" : 1, 
    "b" : 1 
  }, 
  { 
    "_key" : "33847", 
    "_id" : "test/33847", 
    "_rev" : "_cS-WEUm--C", 
    "a" : 1, 
    "x" : 0, 
    "y" : 1, 
    "b" : 1 
  }, 
  { 
    "_key" : "33849", 
    "_id" : "test/33849", 
    "_rev" : "_cS-WEUm--E", 
    "a" : 1, 
    "x" : 0, 
    "y" : 1, 
    "b" : 1 
  } 
]

 

 

 

Previous                                                    Next                                                    Home

ArangoDB: Replace by Example

‘replaceByExample’ method is used to replace the entire document body of matching example with new value.

 

Signature

collection.replaceByExample(example, newValue)

collection.replaceByExample(document, newValue, waitForSync)

collection.replaceByExample(document, newValue, waitForSync, limit)

 

if ‘waitForSync’ parameter is set to true, then it forces the synchronization of replaceByExample operation to disk. . If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied.

 

‘limit’ parameter is used to restrict the number of documents to be affected with this operation.

 

Let’s experiment with an example.

127.0.0.1:8529@abc_org> db.test.toArray()
[ 
  { 
    "_key" : "33825", 
    "_id" : "test/33825", 
    "_rev" : "_cS-_Uj----", 
    "a" : 1, 
    "b" : 1, 
    "c" : 1 
  }, 
  { 
    "_key" : "33827", 
    "_id" : "test/33827", 
    "_rev" : "_cS-_YP----", 
    "a" : 1, 
    "b" : 0, 
    "c" : 1 
  }, 
  { 
    "_key" : "33835", 
    "_id" : "test/33835", 
    "_rev" : "_cS-_bQ2---", 
    "a" : 1, 
    "b" : 0, 
    "c" : 0 
  }, 
  { 
    "_key" : "33837", 
    "_id" : "test/33837", 
    "_rev" : "_cS-_g66---", 
    "a" : 0, 
    "b" : 0, 
    "c" : 0 
  }, 
  { 
    "_key" : "33845", 
    "_id" : "test/33845", 
    "_rev" : "_cS-_lkC---", 
    "a" : 0, 
    "b" : 0, 
    "c" : 1 
  }, 
  { 
    "_key" : "33847", 
    "_id" : "test/33847", 
    "_rev" : "_cS-_qWG---", 
    "a" : 0, 
    "b" : 1, 
    "c" : 0 
  }, 
  { 
    "_key" : "33849", 
    "_id" : "test/33849", 
    "_rev" : "_cS-_tHy---", 
    "a" : 0, 
    "b" : 1, 
    "c" : 1 
  } 
]

 

If a document has {"a" : 0}, then I want to replace it with {"a" : 1, "x" : 1, "y" : 1}.

db.test.replaceByExample({"a" : 0}, {"a" : 1, "x" : 1, "y" : 1})

127.0.0.1:8529@abc_org> db.test.replaceByExample({"a" : 0}, {"a" : 1, "x" : 1, "y" : 1})
4

127.0.0.1:8529@abc_org> db.test.toArray()
[ 
  { 
    "_key" : "33825", 
    "_id" : "test/33825", 
    "_rev" : "_cS-_Uj----", 
    "a" : 1, 
    "b" : 1, 
    "c" : 1 
  }, 
  { 
    "_key" : "33827", 
    "_id" : "test/33827", 
    "_rev" : "_cS-_YP----", 
    "a" : 1, 
    "b" : 0, 
    "c" : 1 
  }, 
  { 
    "_key" : "33835", 
    "_id" : "test/33835", 
    "_rev" : "_cS-_bQ2---", 
    "a" : 1, 
    "b" : 0, 
    "c" : 0 
  }, 
  { 
    "_key" : "33837", 
    "_id" : "test/33837", 
    "_rev" : "_cS-CmaK---", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  }, 
  { 
    "_key" : "33845", 
    "_id" : "test/33845", 
    "_rev" : "_cS-CmaK--A", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  }, 
  { 
    "_key" : "33847", 
    "_id" : "test/33847", 
    "_rev" : "_cS-CmaO---", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  }, 
  { 
    "_key" : "33849", 
    "_id" : "test/33849", 
    "_rev" : "_cS-CmaO--A", 
    "a" : 1, 
    "x" : 1, 
    "y" : 1 
  } 
]

 

 

 

Previous                                                    Next                                                    Home

Neo4j: IN operator

The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.

 

For example, below query return all the persons whose age is either 32 or 45 or 38.

MATCH(n:Person) WHERE n.age IN [32, 45, 38] RETURN n

 

Let’s see the same with an example.

 

Step 1: Open neo4j browser by hitting following url in browser.

http://localhost:7474/browser/

 

 

Step 2: Insert data by executing below query.

CREATE (p1:Person{name: "Rama Krishna", age: 32, city: "Bangalore", male: true, designation: "CEO"}),
(p2:Person{name: "Murali", age: 32, city: "Hyderabad", male: true, designation: "Vice President"}),
(p3:Person{name: "Gopi", age: 34, city: "Chennai", male: true, designation: "Vice President"}),
(p4:Person{name: "Kiran", age: 28, city: "Bangalore", male: true, designation: "Director"}),
(p5:Person{name: "Siva", age: 45, city: "Hyderabad", male: true, designation: "Director"}),
(p6:Person{name: "Kiran", age: 36, city: "Hyderabad", male: true, designation: "Manager"}),
(p7:Person{name: "Ritweek", age: 23, city: "Bangalore", male: true, designation: "Manager"}),
(p8:Person{name: "Sudheer", age: 24, city: "Chennai", male: true, designation: "Manager"}),
(p9:Person{name: "Naveen", age: 37, city: "Bangalore", male: true, designation: "Employee"}),
(p10:Person{name: "Sailaja", age: 31, city: "Hyderabad", female: true, designation: "Employee"}),
(p11:Person{name: "Harika", age: 36, city: "Bangalore", female: true, designation: "Employee"}),
(p12:Person{name: "Brahmam", age: 41, city: "Bangalore", male: true, designation: "Employee"}),
(office1:Location{name: "Pluto", city: "Bangalore"}),
(office2:Location{name: "Mars", city: "Chennai"})
MERGE (p2)-[:REPORT_TO{from: 2014, description: "reports to"}]->(p1)
MERGE (p3)-[:REPORT_TO{from: 2016, description: "reports to"}]->(p1)
MERGE (p4)-[:REPORT_TO{from: 1997, description: "reports to"}]->(p2)
MERGE (p5)-[:REPORT_TO{from: 1997, description: "reports to"}]->(p3)
MERGE (p6)-[:REPORT_TO{from: 2001, description: "reports to"}]->(p4)
MERGE (p7)-[:REPORT_TO{from: 2009, description: "reports to"}]->(p4)
MERGE (p8)-[:REPORT_TO{from: 1998, description: "reports to"}]->(p5)
MERGE (p9)-[:REPORT_TO{from: 2003, description: "reports to"}]->(p6)
MERGE (p10)-[:REPORT_TO{from: 2004, description: "reports to"}]->(p6)
MERGE (p11)-[:REPORT_TO{from: 2008, description: "reports to"}]->(p7)
MERGE (p12)-[:REPORT_TO{from: 2019, description: "reports to"}]->(p8)
MERGE (p2)-[:FRIEND_TO{from: 2014, description: "friend to"}]->(p1)
MERGE (p10)-[:FRIEND_TO{from: 2014, description: "friend to"}]->(p8)
MERGE (p7)-[:FRIEND_TO{from: 2014, description: "friend to"}]->(p9)
MERGE (p3)-[:RELATIVE_TO{from: 2014, description: "relative to"}]->(p4)
RETURN p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, office1, office2

 


Get all the persons whose age is either 32 or 45 or 38.

MATCH(n:Person) WHERE n.age IN [32, 45, 38] RETURN n


 

Previous                                                    Next                                                    Home