这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions testing-modules/jmeter-2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
42 changes: 42 additions & 0 deletions testing-modules/jmeter-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## JMeter

This module contains articles about JMeter.
It contains the code of a simple API for some CRUD operations built using Spring Boot.

### Requirements

- Maven
- JDK 8

### Running

To build and start the server simply type

```bash
$ mvn clean install
$ mvn spring-boot:run -Dserver.port=8989
```

### Available CRUD

You can see what crud operation are available using curl:

```bash
$ curl localhost:8080
```

### Available UUID API

You can view the test response using curl:

```bash
$ curl localhost:8080/api/uuid
```

Now with default configurations it will be available at: [http://localhost:8080](http://localhost:8080)

Enjoy it :)

### Relevant Articles:

-
42 changes: 42 additions & 0 deletions testing-modules/jmeter-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>jmeter-2</artifactId>
<packaging>jar</packaging>
<name>jmeter-2</name>
<description>Intro to Performance testing using JMeter</description>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.baeldung;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringJMeterApplication {

public static void main(String[] args) {
SpringApplication.run(SpringJMeterApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.baeldung.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

import static java.lang.String.format;

@RestController
public class RetrieveUuidController {

@GetMapping("/api/uuid")
public ResponseEntity<String> uuid() {
return ResponseEntity.ok(format("Test message... %s.", UUID.randomUUID()));
}
}
Empty file.
13 changes: 13 additions & 0 deletions testing-modules/jmeter-2/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.baeldung;

import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class SpringJMeterApplicationUnitTest {

@Autowired
private MockMvc mockMvc;

@Test
public void whenClientRequestsGetUuid_thenReceivesValidUuid() throws Exception {
mockMvc.perform(get("/api/uuid"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Test message... ")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.baeldung.controller;

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

import java.util.UUID;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;

@SpringBootTest
class RetrieveUuidControllerUnitTest {

@Autowired
RetrieveUuidController retrieveUuidController;

@Test
void whenGetUuid_thenReturnValidUuid() {
ResponseEntity<String> response = retrieveUuidController.uuid();

assertNotNull(response);
assertNotNull(response.getBody());
String responseBody = response.getBody();
String uuidCandidate = responseBody.substring(16, responseBody.length() - 1);
assertDoesNotThrow(() -> UUID.fromString(uuidCandidate));
assertEquals(uuidCandidate, UUID.fromString(uuidCandidate).toString());
}
}
Loading