Skip to content

Commit

Permalink
chore: merge with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Nov 9, 2023
2 parents be31666 + b52c722 commit ac2fbc2
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM adoptopenjdk/openjdk11
VOLUME ["/tmp","/log"]
EXPOSE 8080
ARG JAR_FILE
COPY ./LiveService.jar app.jar
COPY ./target/LiveService.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
<version>${spring-security.version}</version>
</dependency>

<!-- Spring actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down Expand Up @@ -161,11 +168,13 @@
<artifactId>log4j-to-slf4j</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -202,6 +211,17 @@
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public synchronized void addUser(WebSocketUserSession webSocketUserSession) {
this.subscribedUsers.add(webSocketUserSession);
}

public synchronized void clearAllSessions() {
this.subscribedUsers.clear();
}

/**
* Removes the user session if a session with given id exists.
*
Expand Down Expand Up @@ -66,4 +70,5 @@ public synchronized List<WebSocketUserSession> retrieveAllUsers() {
return new LinkedList<>(this.subscribedUsers);
}


}
5 changes: 5 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ live.event.retry.amount=5
live.event.minimum.seconds.before.retry=1

logging.level.root=WARN

management.endpoint.health.enabled=true
management.endpoint.health.show-details=never
management.endpoints.web.exposure.include=health
management.health.probes.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand All @@ -51,6 +52,11 @@ class LiveServiceApplicationIT extends StompClientIntegrationTest {
@Autowired
private MockMvc mockMvc;

@BeforeEach
void setup() {
socketUserRegistry.clearAllSessions();
}

@Test
void connectToSocket_Should_connect_When_accessTokenIsValid() throws Exception {
var stompSession = performConnect(FIRST_VALID_USER);
Expand Down Expand Up @@ -96,6 +102,7 @@ void connectToSocket_Should_registerExpectedUser_When_accessTokenIsValid() throw
@Test
void subscribe_Should_subscribeUser() throws Exception {
var stompSession = performConnect(FIRST_VALID_USER);

final Subscription subscription = performSubscribe(stompSession);


Expand Down Expand Up @@ -188,7 +195,7 @@ void sendLiveEvent_Should_sendVideoDenyRequestMessageEventToUser_When_userIsSubs
.andExpect(status().isOk());

await()
.atMost(15, SECONDS)
.atMost(25, SECONDS)
.until(receivedMessages::size, is(1));
var resultMessage = receivedMessages.iterator().next();
assertThat(resultMessage, notNullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public abstract class StompClientIntegrationTest extends AbstractJUnit4SpringContextTests {

protected static final String SUBSCRIPTION_ENDPOINT = "/user/events";
protected static final int MESSAGE_TIMEOUT = 5;
protected static final int MESSAGE_TIMEOUT = 10;
protected static final String FIRST_VALID_USER = "firstValidUser";
static final String SECOND_VALID_USER = "secondValidUser";
static final String THIRD_VALID_USER = "thirdValidUser";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.caritas.cob.liveservice.api.controller;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.hamcrest.Matchers.is;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import de.caritas.cob.liveservice.LiveServiceApplication;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@SpringBootTest(classes = LiveServiceApplication.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
@AutoConfigureMockMvc(addFilters = false)
class ActuatorControllerIT {

@Autowired private WebApplicationContext context;

private MockMvc mockMvc;

@BeforeEach
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();
}

@Test
void getHealtcheck_Should_returnHealtcheck() throws Exception {
mockMvc
.perform(get("/actuator/health").contentType(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("status", is("UP")));
}

@Test
void getActuatorEndpoints_Should_returnNotFound_When_ActuatorEndpointsNotExposed() throws Exception {
mockMvc
.perform(get("/actuator/env").contentType(APPLICATION_JSON))
.andExpect(status().isNotFound());

mockMvc
.perform(get("/actuator/beans").contentType(APPLICATION_JSON))
.andExpect(status().isNotFound());
}
}

0 comments on commit ac2fbc2

Please sign in to comment.