Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'chrome-apps-variant' into 1.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
matzew committed Oct 31, 2014
2 parents 8f7b133 + b62099c commit 49cb262
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public boolean isValid(Installation installation, ConstraintValidatorContext con
switch (type) {
case IOS:
return IOS_DEVICE_TOKEN.matcher(deviceToken).matches();
case CHROME_PACKAGED_APP:
case ANDROID:
return ANDROID_DEVICE_TOKEN.matcher(deviceToken).matches();
case SIMPLE_PUSH:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import org.jboss.aerogear.unifiedpush.api.AndroidVariant;
import org.jboss.aerogear.unifiedpush.api.Category;
import org.jboss.aerogear.unifiedpush.api.ChromePackagedAppVariant;
import org.jboss.aerogear.unifiedpush.api.Installation;
import org.jboss.aerogear.unifiedpush.api.PushApplication;
import org.jboss.aerogear.unifiedpush.api.SimplePushVariant;
import org.jboss.aerogear.unifiedpush.api.Variant;
import org.jboss.aerogear.unifiedpush.api.iOSVariant;
import org.jboss.aerogear.unifiedpush.dao.PageResult;
import org.jboss.aerogear.unifiedpush.jpa.dao.impl.JPAInstallationDao;
Expand Down Expand Up @@ -374,7 +376,6 @@ public void findPushEndpointsWithoutDeviceType() {
assertThat(tokens.get(0)).startsWith("http://server:8080/update/");
}


@Test
public void shouldValidateDeviceId() {
// given
Expand Down Expand Up @@ -411,13 +412,9 @@ public void shouldSaveWhenValidateDeviceIdIOS() {
final iOSVariant variant = new iOSVariant();
variant.setPassphrase("12");
variant.setCertificate("12".getBytes());
entityManager.persist(variant);

installation.setVariant(variant);

// when
installationDao.create(installation);
entityManager.flush();
deviceTokenTest(installation, variant);
}

@Test(expected = ConstraintViolationException.class)
Expand All @@ -427,13 +424,24 @@ public void shouldNotSaveWhenSimplePushTokenInvalid() {
installation.setDeviceToken("htp://invalid");

final SimplePushVariant variant = new SimplePushVariant();
entityManager.persist(variant);

installation.setVariant(variant);

// when
installationDao.create(installation);
entityManager.flush();
deviceTokenTest(installation, variant);
}

@Test
public void shouldSaveWhenValidChromeApp() {
// given
final Installation installation = new Installation();
installation.setDeviceToken(DEVICE_TOKEN_1);

final ChromePackagedAppVariant variant = new ChromePackagedAppVariant();
variant.setClientId("12");
variant.setClientSecret("12");
variant.setRefreshToken("12");

//when
deviceTokenTest(installation, variant);
}

@Test
Expand All @@ -443,13 +451,9 @@ public void shouldSaveWhenSimplePushTokenValid() {
installation.setDeviceToken("http://valid/but/you/should/use/https");

final SimplePushVariant variant = new SimplePushVariant();
entityManager.persist(variant);

installation.setVariant(variant);

// when
installationDao.create(installation);
entityManager.flush();
deviceTokenTest(installation, variant);
}

@Test
Expand All @@ -463,6 +467,12 @@ public void shouldSaveWhenValidateDeviceIdAndroid() {
final AndroidVariant variant = new AndroidVariant();
variant.setGoogleKey("12");
variant.setProjectNumber("12");

// when
deviceTokenTest(installation, variant);
}

private void deviceTokenTest(Installation installation, Variant variant) {
entityManager.persist(variant);
installation.setVariant(variant);

Expand Down

0 comments on commit 49cb262

Please sign in to comment.