-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into ingame_metric
- Loading branch information
Showing
185 changed files
with
5,031 additions
and
2,246 deletions.
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
...est/java/org/terasology/identity/storageServiceClient/BigIntegerBase64SerializerTest.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,38 @@ | ||
/* | ||
* Copyright 2017 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terasology.identity.storageServiceClient; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonPrimitive; | ||
import org.junit.Test; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class BigIntegerBase64SerializerTest { | ||
|
||
@Test | ||
public void testSerializer() { | ||
BigIntegerBase64Serializer serializer = new BigIntegerBase64Serializer(); | ||
BigInteger data = new BigInteger("123456789123456789123456789123456789"); | ||
JsonElement serialized = serializer.serialize(data, null, null); | ||
assertTrue(serialized.isJsonPrimitive()); | ||
assertTrue(((JsonPrimitive) serialized).isString()); | ||
assertEquals(data, serializer.deserialize(serialized, null, null)); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ts/src/test/java/org/terasology/identity/storageServiceClient/ServiceApiRequestTests.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,68 @@ | ||
/* | ||
* Copyright 2017 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terasology.identity.storageServiceClient; | ||
|
||
|
||
import com.google.gson.Gson; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ServiceApiRequestTests { | ||
|
||
static class DummySerializableObject { | ||
private String fieldA; | ||
private int fieldB; | ||
|
||
private DummySerializableObject(String fieldA, int fieldB) { | ||
this.fieldA = fieldA; | ||
this.fieldB = fieldB; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (!(other instanceof DummySerializableObject)) { | ||
return false; | ||
} | ||
DummySerializableObject o = (DummySerializableObject) other; | ||
return fieldA.equals(o.fieldA) && fieldB == o.fieldB; | ||
} | ||
} | ||
|
||
@Test | ||
public void testRequest() throws IOException, StorageServiceException { | ||
Gson gson = new Gson(); | ||
HttpURLConnection mockedConn = mock(HttpURLConnection.class); | ||
ByteArrayOutputStream receivedRequest = new ByteArrayOutputStream(); | ||
ByteArrayInputStream response = new ByteArrayInputStream("{\"fieldA\":\"response\", \"fieldB\": 1}".getBytes()); | ||
|
||
when(mockedConn.getOutputStream()).thenReturn(receivedRequest); | ||
when(mockedConn.getInputStream()).thenReturn(response); | ||
when(mockedConn.getResponseCode()).thenReturn(200); | ||
|
||
DummySerializableObject reqData = new DummySerializableObject("request", 0); | ||
DummySerializableObject resData = ServiceApiRequest.request(mockedConn, HttpMethod.GET, null, reqData, DummySerializableObject.class); | ||
assertEquals(gson.toJson(reqData), receivedRequest.toString()); | ||
assertEquals(new DummySerializableObject("response", 1), resData); | ||
} | ||
} |
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
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
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
48 changes: 48 additions & 0 deletions
48
engine/src/main/java/org/terasology/config/IdentityStorageServiceConfig.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,48 @@ | ||
/* | ||
* Copyright 2017 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terasology.config; | ||
|
||
import java.net.URL; | ||
|
||
/** | ||
* Used to keep track of storage service URL and session token. | ||
*/ | ||
public class IdentityStorageServiceConfig { | ||
|
||
private URL serviceURL; | ||
private String sessionToken; | ||
|
||
public boolean isSet() { | ||
return serviceURL != null && sessionToken != null; | ||
} | ||
|
||
public URL getServiceUrl() { | ||
return serviceURL; | ||
} | ||
|
||
public String getSessionToken() { | ||
return sessionToken; | ||
} | ||
|
||
public void setServiceURL(URL serviceURL) { | ||
this.serviceURL = serviceURL; | ||
} | ||
|
||
public void setSessionToken(String sessionToken) { | ||
this.sessionToken = sessionToken; | ||
} | ||
|
||
} |
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
Oops, something went wrong.