Thursday, 12 August 2021

Junit5: RepetitionInfoParameterResolver: Retrieve information about current repetition

If a method parameter in a @RepeatedTest, @BeforeEach, or @AfterEach method is of type RepetitionInfo, the RepetitionInfoParameterResolver will supply an instance of RepetitionInfo. RepetitionInfo can then be used to retrieve information about the current repetition and the total number of repetitions for the corresponding @RepeatedTest.

 

RepetitionInfoDemo.java

package com.sample.app;

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

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.RepetitionInfo;

public class RepetitionInfoDemo {
	
	private static void printRepetitionInfo(RepetitionInfo repetitionInfo) {
		int currentRepetition = repetitionInfo.getCurrentRepetition();
		int totalRepetitions = repetitionInfo.getTotalRepetitions();
		System.out.println("currentRepetition : " + currentRepetition + " , " + "totalRepetitions : " + totalRepetitions);
	}
	
	@BeforeEach
	public void setup(RepetitionInfo repetitionInfo) {
		System.out.println("\nInside Setup method");
		printRepetitionInfo(repetitionInfo);
	}
	
	@DisplayName("TestCase1")
	@RepeatedTest(value = 3, name = "{displayName} {currentRepetition}/{totalRepetitions}")
	void test1(RepetitionInfo repetitionInfo) {
		System.out.println("Inside test1 method");
		printRepetitionInfo(repetitionInfo);
		assertTrue(true);
	}
	
	@AfterEach
	public void cleanup(RepetitionInfo repetitionInfo) {
		System.out.println("Inside cleanup method");
		printRepetitionInfo(repetitionInfo);
	}
	


}

  When you ran above test, you will see below messages in console.

 

Inside Setup method
currentRepetition : 1 , totalRepetitions : 3
Inside test1 method
currentRepetition : 1 , totalRepetitions : 3
Inside cleanup method
currentRepetition : 1 , totalRepetitions : 3

Inside Setup method
currentRepetition : 2 , totalRepetitions : 3
Inside test1 method
currentRepetition : 2 , totalRepetitions : 3
Inside cleanup method
currentRepetition : 2 , totalRepetitions : 3

Inside Setup method
currentRepetition : 3 , totalRepetitions : 3
Inside test1 method
currentRepetition : 3 , totalRepetitions : 3
Inside cleanup method
currentRepetition : 3 , totalRepetitions : 3

 

junit report looks like below.

 


 

Previous                                                    Next                                                    Home

Neo4j: Query by label and properties

Syntax

MATCH (n:label{property1: value1, property2: value2....propertyN: valueN}) RETURN n

 

Let’s see it 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]->(p1)
MERGE (p3)-[:REPORT_TO]->(p1)
MERGE (p4)-[:REPORT_TO]->(p2)
MERGE (p5)-[:REPORT_TO]->(p3)
MERGE (p6)-[:REPORT_TO]->(p4)
MERGE (p7)-[:REPORT_TO]->(p4)
MERGE (p8)-[:REPORT_TO]->(p5)
MERGE (p9)-[:REPORT_TO]->(p6)
MERGE (p10)-[:REPORT_TO]->(p6)
MERGE (p11)-[:REPORT_TO]->(p7)
MERGE (p12)-[:REPORT_TO]->(p8)
RETURN p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, office1, office2




Get all the nodes with label Location

MATCH (n:Location) RETURN n



Previous                                                    Next                                                    Home

Neo4j: Limit number of nodes from query result

Using LIMIT clause, you can limit number of nodes returned from the query result.

 

Syntax

MATCH (n) RETURN n LIMIT NUMBER_OF_ITEMS

 

Example

MATCH (n) RETURN n LIMIT 4

 

Let’s see it 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]->(p1)
MERGE (p3)-[:REPORT_TO]->(p1)
MERGE (p4)-[:REPORT_TO]->(p2)
MERGE (p5)-[:REPORT_TO]->(p3)
MERGE (p6)-[:REPORT_TO]->(p4)
MERGE (p7)-[:REPORT_TO]->(p4)
MERGE (p8)-[:REPORT_TO]->(p5)
MERGE (p9)-[:REPORT_TO]->(p6)
MERGE (p10)-[:REPORT_TO]->(p6)
MERGE (p11)-[:REPORT_TO]->(p7)
MERGE (p12)-[:REPORT_TO]->(p8)
RETURN p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, office1, office2

 


 

Step 3: Execute below query to get all the nodes.

MATCH (n) RETURN n LIMIT 4

 



Previous                                                    Next                                                    Home

ArangoDB: any: Get any one document

collection.any()

This method return a random document from the given collection. It return null if no document exists.

127.0.0.1:8529@abc_org> db.user.any()
{ 
  "_key" : "17089", 
  "_id" : "user/17089", 
  "_rev" : "_cRe1GKq---", 
  "id" : 1, 
  "firstName" : "Sailu", 
  "lastName" : "Ptr", 
  "age" : 32 
}

 

 

 

Previous                                                    Next                                                    Home

ArangoDB: range, closedRange: Get all the documents where attribute is in given range

Signature

collection.range(attribute, left, right)

collection.closedRange(attribute, left, right)

 

‘range’ method returns all the documents from a collection such that the attribute is greater or equal than left and strictly less than right.

 

‘closedRange’ method returns all documents of a collection such that the attribute is greater or equal than left and less or equal than right.

 

Nested attributes are represented using . notation (like a.b.c)

 

All the documents from user collection

127.0.0.1:8529@abc_org> db.user.all().toArray()
[ 
  { 
    "_key" : "17089", 
    "_id" : "user/17089", 
    "_rev" : "_cRe1GKq---", 
    "id" : 1, 
    "firstName" : "Sailu", 
    "lastName" : "Ptr", 
    "age" : 32 
  }, 
  { 
    "_key" : "17091", 
    "_id" : "user/17091", 
    "_rev" : "_cRe1GKu---", 
    "id" : 2, 
    "firstName" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "17093", 
    "_id" : "user/17093", 
    "_rev" : "_cRe1GKy---", 
    "id" : 3, 
    "firstName" : "Krishna", 
    "lastName" : "Gurram", 
    "age" : 32 
  }, 
  { 
    "_key" : "17095", 
    "_id" : "user/17095", 
    "_rev" : "_cRe1H-6---", 
    "id" : 4, 
    "firstName" : "Venkat", 
    "lastName" : "Ptr", 
    "age" : 35 
  } 
]

range method example

127.0.0.1:8529@abc_org> db.user.range("age", 32, 35).toArray()
[ 
  { 
    "_key" : "17089", 
    "_id" : "user/17089", 
    "_rev" : "_cRe1GKq---", 
    "id" : 1, 
    "firstName" : "Sailu", 
    "lastName" : "Ptr", 
    "age" : 32 
  }, 
  { 
    "_key" : "17091", 
    "_id" : "user/17091", 
    "_rev" : "_cRe1GKu---", 
    "id" : 2, 
    "firstName" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "17093", 
    "_id" : "user/17093", 
    "_rev" : "_cRe1GKy---", 
    "id" : 3, 
    "firstName" : "Krishna", 
    "lastName" : "Gurram", 
    "age" : 32 
  } 
]


closedRange method example

127.0.0.1:8529@abc_org> db.user.closedRange("age", 32, 35).toArray()
[ 
  { 
    "_key" : "17089", 
    "_id" : "user/17089", 
    "_rev" : "_cRe1GKq---", 
    "id" : 1, 
    "firstName" : "Sailu", 
    "lastName" : "Ptr", 
    "age" : 32 
  }, 
  { 
    "_key" : "17091", 
    "_id" : "user/17091", 
    "_rev" : "_cRe1GKu---", 
    "id" : 2, 
    "firstName" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "17093", 
    "_id" : "user/17093", 
    "_rev" : "_cRe1GKy---", 
    "id" : 3, 
    "firstName" : "Krishna", 
    "lastName" : "Gurram", 
    "age" : 32 
  }, 
  { 
    "_key" : "17095", 
    "_id" : "user/17095", 
    "_rev" : "_cRe1H-6---", 
    "id" : 4, 
    "firstName" : "Venkat", 
    "lastName" : "Ptr", 
    "age" : 35 
  } 
]


Previous                                                    Next                                                    Home

Monday, 9 August 2021

ArangoDB: firstExample: Get one document that matches to given example

‘collection.firstExample(example)’ method return one document that matches to given example. If not document matches to given example, it return null.

127.0.0.1:8529@abc_org> db.user.all().toArray()
[ 
  { 
    "_key" : "15950", 
    "_id" : "user/15950", 
    "_rev" : "_cReaqJC---", 
    "id" : 1, 
    "firstname" : "Sailu", 
    "lastName" : "Ptr", 
    "age" : 32 
  }, 
  { 
    "_key" : "15970", 
    "_id" : "user/15970", 
    "_rev" : "_cRebGD2---", 
    "id" : 2, 
    "firstname" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "15978", 
    "_id" : "user/15978", 
    "_rev" : "_cRebX7q---", 
    "id" : 3, 
    "firstname" : "Krishna", 
    "lastName" : "Gurram", 
    "age" : 32 
  }, 
  { 
    "_key" : "15998", 
    "_id" : "user/15998", 
    "_rev" : "_cRebx9K---", 
    "id" : 4, 
    "firstname" : "Venkat", 
    "lastName" : "Ptr", 
    "age" : 35 
  } 
]

Let’s get one user document whose age is 32.

127.0.0.1:8529@abc_org> db.user.firstExample({"age": 32})
{ 
  "_key" : "15950", 
  "_id" : "user/15950", 
  "_rev" : "_cReaqJC---", 
  "id" : 1, 
  "firstname" : "Sailu", 
  "lastName" : "Ptr", 
  "age" : 32 
}


Let’s get one user document whose age is 40.

127.0.0.1:8529@abc_org> db.user.firstExample({"age": 40})
null


Alternative syntax

collection.firstExample(path1, value1, ...)

127.0.0.1:8529@abc_org> db.user.firstExample("age", 32, "firstname", "Sailu")
{ 
  "_key" : "15950", 
  "_id" : "user/15950", 
  "_rev" : "_cReaqJC---", 
  "id" : 1, 
  "firstname" : "Sailu", 
  "lastName" : "Ptr", 
  "age" : 32 
}


 

Previous                                                    Next                                                    Home

Neo4j: Get all the nodes

Syntax

MATCH (n) RETURN n

 

Above statement return all the nodes. Here ‘n’ stands for any node.

 

Let’s see it 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]->(p1)
MERGE (p3)-[:REPORT_TO]->(p1)
MERGE (p4)-[:REPORT_TO]->(p2)
MERGE (p5)-[:REPORT_TO]->(p3)
MERGE (p6)-[:REPORT_TO]->(p4)
MERGE (p7)-[:REPORT_TO]->(p4)
MERGE (p8)-[:REPORT_TO]->(p5)
MERGE (p9)-[:REPORT_TO]->(p6)
MERGE (p10)-[:REPORT_TO]->(p6)
MERGE (p11)-[:REPORT_TO]->(p7)
MERGE (p12)-[:REPORT_TO]->(p8)
RETURN p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, office1, office2

 


 

Step 3: Execute below query to get all the nodes.

MATCH (n) RETURN n



 

Previous                                                    Next                                                    Home