Skip to content
Snippets Groups Projects
Commit 7aeccc86 authored by Sven Graupner's avatar Sven Graupner
Browse files

initial checking, version v1.0

parent 65a0754d
No related branches found
Tags v1.0
No related merge requests found
.classpath
.project
.settings
target
# se2-Application
# se2-Application, v1.0
Demo application of the Software Engineering 2 course.
pom.xml 0 → 100644
<project
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<!-- Parent project file.
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
<properties>
<project.version>1.0.0</project.version>
<springboot.version>2.1.8.RELEASE</springboot.version>
<junit.version>4.12</junit.version>
<maven.test.skip>false</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.compiler.source>1.12</project.compiler.source>
<project.compiler.target>1.12</project.compiler.target>
</properties>
<!-- This project. -->
<groupId>de.beuth</groupId>
<artifactId>se2-application</artifactId>
<version>${project.version}-SNAPSHOT</version>
<name>se2-application</name>
<description>Software Engineering 2 application with Spring Boot</description>
<packaging>jar</packaging>
<!-- Project dependencies. -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Configurations for build stage. -->
<build>
<plugins>
<!-- Use Spring Boots maven build plugin. -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.application.se2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
/**
* SpringBoot's main Application class containing Java's main() method with invocation
* and launch of Spring's run time.
*
* @author sgra64
*
*/
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {
/**
* Protected constructor for Spring Boot to create an Application instance.
* Application instances must be created by Spring, never by "new".
* @param args arguments passed from main()
*/
Application( String[] args ) {
System.out.println( "2. Hello SpringApplication, Constructor called." );
}
/**
* Entry point after Spring Boot has initialized the application instance.
*/
@EventListener(ApplicationReadyEvent.class)
public void doSomethingAfterStartup() {
System.out.println( "3. Hello SpringApplication, doSomethingAfterStartup() called." );
}
/**
* Java's main() method.
*
* @param args arguments passed from invoking command.
*/
public static void main( final String ... args ) {
System.out.println( "1. Hello SpringApplication!" );
System.out.print( " Initialize Spring Boot and create Application instance." );
// Initialize Spring Boot and create Application instance.
ApplicationContext applicationContext = SpringApplication.run( Application.class, args );
System.out.println( "4. Bye, SpringApplication, " + applicationContext.getId() + "!" );
}
/**
* Return the Application name.
*
* @return Application name.
*/
public String getName() {
return "se2-application";
}
}
package com.application.se2;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* Entry unit testing class defining test suite.
* See for details:
* - https://stackoverflow.com/questions/43192046/test-suite-run-spring-boot-once
*
* @author sgra64
*
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestCases_ApplicationName.class, //test cases
//TestCases_ApplicationLogic.class //test cases ...
})
public class ApplicationTest {
}
package com.application.se2;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Unit tests concerning the Application's name.
*
* @author sgra64
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes={com.application.se2.Application.class})
public class TestCases_ApplicationName {
@Autowired
private Application application; // auto-wired reference to Application instance
@Test
public void applicationNameTest() {
String name = application.getName();
assertTrue( "se2-application".equals( name ) );
}
@Test
public void applicationNameLengthTest() {
String name = application.getName();
assertTrue( name != null && name.length() == 15 );
}
@Test
public void applicationNameStartsWithSE2Test() {
String name = application.getName();
assertTrue( name != null && name.startsWith( "se2" ) );
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment