Sunday, 5 September 2021

Neo4j: AS: Rename the properties

AS clause is used to rename the property names that are returned in query result.

 

Example

MATCH (p:Person) RETURN p.name AS My_Name, p.salary AS My_Salary, p.age AS My_Age ORDER BY p.age

 

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", salary:540000000}),
(p2:Person{name: "Murali", age: 32, city: "Hyderabad", male: true, designation: "Vice President", salary: 43000000}),
(p3:Person{name: "Gopi", age: 34, city: "Chennai", male: true, designation: "Vice President", salary: 63067000}),
(p4:Person{name: "Kiran", age: 28, city: "Bangalore", male: true, designation: "Director", salary: 12000000}),
(p5:Person{name: "Siva", age: 45, city: "Hyderabad", male: true, designation: "Director", salary: 23000000}),
(p6:Person{name: "Kiran", age: 36, city: "Hyderabad", male: true, designation: "Manager", salary: 7800000}),
(p7:Person{name: "Ritweek", age: 23, city: "Bangalore", male: true, designation: "Manager", salary: 8100000}),
(p8:Person{name: "Sudheer", age: 24, city: "Chennai", male: true, designation: "Manager", salary: 7900000}),
(p9:Person{name: "Naveen", age: 37, city: "Bangalore", male: true, designation: "Employee", salary: 4500000}),
(p10:Person{name: "Sailaja", age: 31, city: "Hyderabad", female: true, designation: "Employee", salary: 5300000}),
(p11:Person{name: "Harika", age: 36, city: "Bangalore", female: true, designation: "Employee", salary: 3400000}),
(p12:Person{name: "Brahmam", age: 41, city: "Bangalore", male: true, designation: "Employee", salary: 4560000}),
(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


 

Step 3: Execute the query using AS clause.

MATCH (p:Person) RETURN p.name AS My_Name, p.salary AS My_Salary, p.age AS My_Age ORDER BY p.age

 




 

 

Previous                                                    Next                                                    Home

Junit5: Test Suite: ExcludeTags

@ExcludeTags specifies the tags or tag expressions to be excluded 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 sub packages.

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

}


What if you want to selectively run the test classes that do not matches given tags?

You can use @ExcludeTags annotation to explicitly exclude the classes that do not match to given tags.

 

Example

@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectPackages({"com.sample.app.dummy"})
@ExcludeTags({"prod", "qa"})
public class ExcludeTagsDemo {

}


Above snippet execute below test classes.

a.   Dummy1D2Test

b.   Dummy1Test

c.    Dummy2D1Test

 

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.Tag;
import org.junit.jupiter.api.Test;

@Tag("prod")
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.Tag;
import org.junit.jupiter.api.Test;

@Tag("qa")
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.Tag;
import org.junit.jupiter.api.Test;

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


ExcludeTagsDemo.java

package com.sample.app.suite;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.ExcludeTags;
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"})
@ExcludeTags({"prod", "qa"})
public class ExcludeTagsDemo {

}


Run above application, you will see the executed test classes information in junit report window.






Previous                                                    Next                                                    Home

Junit5: Test Suite: @IncludeTags

@IncludeTags specifies the tags or tag expressions 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 sub packages.

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

}

 

What if you want to selectively run the test classes that matches given tags?

You can use @IncludeTags annotation to explicitly include the classes that matches to given tags.

 

Example

 

@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectPackages({"com.sample.app.dummy"})
@IncludeTags({"prod", "qa"})
public class IncludeTagsDemo {

}

 

Above snippet execute below test classes.

 

a.   DummyTest

b.   Dummy1D1Test

 

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.Tag;
import org.junit.jupiter.api.Test;

@Tag("prod")
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.Tag;
import org.junit.jupiter.api.Test;

@Tag("qa")
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.Tag;
import org.junit.jupiter.api.Test;

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

 

IncludeTagsDemo.java

package com.sample.app.suite;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.IncludeTags;
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"})
@IncludeTags({"prod", "qa"})
public class IncludeTagsDemo {

}

  Run above application, you will see the executed test classes information in junit report window.

 


 

 

 


 

Previous                                                    Next                                                    Home