This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf542c3
commit 026e5e1
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/test/java/net/yogstation/api/controller/BanControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.yogstation.api.controller; | ||
|
||
import net.yogstation.api.bean.AuthorizedSession; | ||
import net.yogstation.api.jpa.entity.BanEntity; | ||
import org.assertj.core.util.Sets; | ||
import org.junit.Assert; | ||
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.data.domain.Page; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.Set; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@ActiveProfiles("development") | ||
public class BanControllerTest { | ||
|
||
@Autowired | ||
private BanController banController; | ||
|
||
@Autowired | ||
private AuthorizedSession authorizedSession; | ||
|
||
@Test | ||
public void test_getBans() { | ||
Page<BanEntity> bans = banController.getBans(0, 25); | ||
|
||
Assert.assertNotNull(bans); | ||
Assert.assertEquals(5, bans.getTotalElements()); | ||
Assert.assertEquals(1, bans.getTotalPages()); | ||
Assert.assertNull(bans.getContent().get(0).getIp()); | ||
Assert.assertNull(bans.getContent().get(0).getComputerid()); | ||
} | ||
|
||
@Test | ||
public void test_getBans_cidAndIPPermissions() { | ||
Set<String> permissions = Sets.newLinkedHashSet("bans.GDPR"); | ||
authorizedSession.setPermissions(permissions); | ||
Page<BanEntity> bans = banController.getBans(0, 25); | ||
|
||
Assert.assertNotNull(bans); | ||
Assert.assertEquals(5, bans.getTotalElements()); | ||
Assert.assertEquals(1, bans.getTotalPages()); | ||
Assert.assertNotNull(bans.getContent().get(0).getIp()); | ||
Assert.assertNotNull(bans.getContent().get(0).getComputerid()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/net/yogstation/api/service/BanServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.yogstation.api.service; | ||
|
||
|
||
import net.yogstation.api.jpa.entity.BanEntity; | ||
import net.yogstation.api.jpa.repository.BanRepository; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BanServiceTest { | ||
|
||
@Mock | ||
private BanRepository banRepository; | ||
|
||
@InjectMocks | ||
private BanService banService; | ||
|
||
@Test | ||
public void test_getBans() { | ||
banService.getBans(4, 25); | ||
|
||
Mockito.verify(banRepository).findAll(Mockito.anyObject(), Mockito.eq(PageRequest.of(4, 25))); | ||
} | ||
} |