-
Notifications
You must be signed in to change notification settings - Fork 29
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
51fb4e7
commit 9d8fcfa
Showing
7 changed files
with
277 additions
and
1 deletion.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
src/main/java/com/faforever/api/data/domain/HardwareInformation.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,116 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.yahoo.elide.annotation.DeletePermission; | ||
import com.yahoo.elide.annotation.Include; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.JoinTable; | ||
import javax.persistence.ManyToMany; | ||
import javax.persistence.Table; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Include(rootLevel = true, type = "HardwareInformation") | ||
@Table(name = "uniqueid") | ||
@DeletePermission(expression = "Prefab.Role.None") | ||
@Setter | ||
public class HardwareInformation { | ||
|
||
private int legacyId; | ||
private String hash; | ||
private String uuid; | ||
private String memSerialNumber; | ||
private String deviceId; | ||
private String manufacturer; | ||
private String name; | ||
private String processorId; | ||
private String smbiosbiosVersion; | ||
private String serialNumber; | ||
private String volumeSerialNumber; | ||
private List<Player> players; | ||
|
||
|
||
@Column(name = "id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
public Integer getLegacyId() { | ||
return legacyId; | ||
} | ||
|
||
@Id | ||
@Column(name = "hash") | ||
@Size(max = 32) | ||
@NotNull | ||
public String getHash() { | ||
return hash; | ||
} | ||
|
||
@Column(name = "uuid") | ||
@NotNull | ||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
@Column(name = "mem_SerialNumber") | ||
@NotNull | ||
public String getMemSerialNumber() { | ||
return memSerialNumber; | ||
} | ||
|
||
@Column(name = "deviceID") | ||
@NotNull | ||
public String getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
@Column(name = "manufacturer") | ||
@NotNull | ||
public String getManufacturer() { | ||
return manufacturer; | ||
} | ||
|
||
@Column(name = "name") | ||
@NotNull | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Column(name = "processorId") | ||
@NotNull | ||
public String getProcessorId() { | ||
return processorId; | ||
} | ||
|
||
@Column(name = "SMBIOSBIOSVersion") | ||
@NotNull | ||
public String getSmbiosbiosVersion() { | ||
return smbiosbiosVersion; | ||
} | ||
|
||
@Column(name = "serialNumber") | ||
@NotNull | ||
public String getSerialNumber() { | ||
return serialNumber; | ||
} | ||
|
||
@Column(name = "volumeSerialNumber") | ||
@NotNull | ||
public String getVolumeSerialNumber() { | ||
return volumeSerialNumber; | ||
} | ||
|
||
@ManyToMany | ||
@JoinTable(name = "unique_id_users", | ||
joinColumns = @JoinColumn(name = "uniqueid_hash", referencedColumnName = "hash"), | ||
inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id")) | ||
public List<Player> getPlayers() { | ||
return this.players; | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/faforever/api/hardwareinformation/HardwareInformationRepository.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,9 @@ | ||
package com.faforever.api.hardwareinformation; | ||
|
||
import com.faforever.api.data.domain.HardwareInformation; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface HardwareInformationRepository extends JpaRepository<HardwareInformation, Integer> { | ||
} |
95 changes: 95 additions & 0 deletions
95
src/test/java/com/faforever/api/data/JsonApiHardwareInformationIntegrationTest.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,95 @@ | ||
package com.faforever.api.data; | ||
|
||
import com.faforever.api.data.domain.Player; | ||
import com.faforever.integration.TestDatabase; | ||
import com.faforever.integration.factories.HardwareInformationFactory; | ||
import com.faforever.integration.factories.PlayerFactory; | ||
import com.faforever.integration.utils.MockMvcHelper; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import javax.inject.Inject; | ||
import javax.servlet.Filter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertEquals; | ||
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; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@Import(TestDatabase.class) | ||
public class JsonApiHardwareInformationIntegrationTest { | ||
|
||
private MockMvc mvc; | ||
private WebApplicationContext context; | ||
private Filter springSecurityFilterChain; | ||
|
||
private TestDatabase database; | ||
|
||
|
||
@Inject | ||
public void init(TestDatabase database, | ||
WebApplicationContext context, | ||
Filter springSecurityFilterChain) { | ||
this.context = context; | ||
this.springSecurityFilterChain = springSecurityFilterChain; | ||
this.database = database; | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
mvc = MockMvcBuilders | ||
.webAppContextSetup(context) | ||
.addFilter(springSecurityFilterChain) | ||
.build(); | ||
database.assertEmptyDatabase(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
// TODO: This is needed, because Elide has some problems with @Transactional annotation #71 | ||
database.tearDown(); | ||
} | ||
|
||
|
||
@Test | ||
public void getHardwareInformation() throws Exception { | ||
List<Player> players = Arrays.asList( | ||
PlayerFactory.create("Alice", "1234", database), | ||
PlayerFactory.create("Bob", "1234", database), | ||
PlayerFactory.create("Charlie", "1234", database), | ||
PlayerFactory.create("Dave", "1234", database), | ||
PlayerFactory.create("Elice", "1234", database) | ||
); | ||
|
||
HardwareInformationFactory.builder() | ||
.hash("1-2-3-4") | ||
.players(players) | ||
.database(database) | ||
.build(); | ||
|
||
assertEquals(1, database.getHardwareInformationRepository().count()); | ||
MockMvcHelper.of(this.mvc).perform( | ||
get("/data/HardwareInformation/")) | ||
.andExpect(jsonPath("$.data", hasSize(1))) | ||
.andExpect(jsonPath("$.data[0].type", is("HardwareInformation"))) | ||
.andExpect(jsonPath("$.data[0].relationships.players.data", hasSize(players.size()))) | ||
.andExpect(status().isOk()); | ||
assertEquals(1, database.getHardwareInformationRepository().count()); | ||
} | ||
|
||
// TODO: implement more test if permission system is ready #81 | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/test/java/com/faforever/integration/factories/HardwareInformationFactory.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,42 @@ | ||
package com.faforever.integration.factories; | ||
|
||
import com.faforever.api.data.domain.HardwareInformation; | ||
import com.faforever.api.data.domain.Player; | ||
import com.faforever.integration.TestDatabase; | ||
import lombok.Builder; | ||
import lombok.Singular; | ||
import org.springframework.util.Assert; | ||
|
||
import java.util.List; | ||
|
||
import static junitx.framework.ComparableAssert.assertEquals; | ||
|
||
public class HardwareInformationFactory { | ||
public static final String DEFAULT_VALUE = "-"; | ||
|
||
@Builder | ||
private static HardwareInformation create(String hash, String uuid, String MemSerialNumber, | ||
String device, String manufacturer, String name, | ||
String processor, String biosVersion, String serialNumber, | ||
String volumeSerialNumber, @Singular List<Player> players, TestDatabase database) { | ||
Assert.notNull(database, "'database' must not be null"); | ||
Assert.notNull(hash, "'hash' must not be null"); | ||
long count = database.getHardwareInformationRepository().count(); | ||
HardwareInformation entity = new HardwareInformation() | ||
.setHash(hash) | ||
.setUuid(uuid != null ? uuid : DEFAULT_VALUE) | ||
.setMemSerialNumber(MemSerialNumber != null ? MemSerialNumber : DEFAULT_VALUE) | ||
.setDeviceId(device != null ? device : DEFAULT_VALUE) | ||
.setManufacturer(manufacturer != null ? manufacturer : DEFAULT_VALUE) | ||
.setName(name != null ? name : DEFAULT_VALUE) | ||
.setProcessorId(processor != null ? processor : DEFAULT_VALUE) | ||
.setSmbiosbiosVersion(biosVersion != null ? biosVersion : DEFAULT_VALUE) | ||
.setSerialNumber(serialNumber != null ? serialNumber : DEFAULT_VALUE) | ||
.setVolumeSerialNumber(volumeSerialNumber != null ? volumeSerialNumber : DEFAULT_VALUE) | ||
.setPlayers(players); | ||
|
||
entity = database.getHardwareInformationRepository().save(entity); | ||
assertEquals(count + 1, database.getHardwareInformationRepository().count()); | ||
return entity; | ||
} | ||
} |
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