<commit_before>package org.sagebionetworks.bridge.sdk.integration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.sagebionetworks.bridge.rest.model.Role.DEVELOPER;
import static org.sagebionetworks.bridge.rest.model.TemplateType.EMAIL_ACCOUNT_EXISTS;
import static org.sagebionetworks.bridge.rest.model.TemplateType.SMS_APP_INSTALL_LINK;

import com.google.common.collect.ImmutableMap;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.sagebionetworks.bridge.rest.api.ForAdminsApi;
import org.sagebionetworks.bridge.rest.api.ForDevelopersApi;
import org.sagebionetworks.bridge.rest.exceptions.EntityNotFoundException;
import org.sagebionetworks.bridge.rest.model.Criteria;
import org.sagebionetworks.bridge.rest.model.GuidVersionHolder;
import org.sagebionetworks.bridge.rest.model.Template;
import org.sagebionetworks.bridge.rest.model.TemplateList;
import org.sagebionetworks.bridge.user.TestUserHelper;
import org.sagebionetworks.bridge.user.TestUserHelper.TestUser;

public class TemplateTest {
    
    TestUser admin;
    TestUser developer;
    Template template;
    
    @Before
    public void before() throws Exception {
        admin = TestUserHelper.getSignedInAdmin();
        developer = TestUserHelper.createAndSignInUser(TemplateTest.class, true, DEVELOPER);
    }
    
    @After
    public void after() throws Exception {
        // in case of earlier test failure, clean up
        if (template != null && template.getGuid() != null) {
            ForAdminsApi adminsApi = admin.getClient(ForAdminsApi.class);
            adminsApi.deleteTemplate(template.getGuid(), true).execute();
        }
        developer.signOutAndDeleteUser();
    }
    
    @Test
    public void crudTemplate() throws Exception {
        Criteria criteria = new Criteria();
        criteria.setMinAppVersions(ImmutableMap.of("Android", 10));
        criteria.setMaxAppVersions(ImmutableMap.of("Android", 100));
        
        // create template
        template = new Template();
        template.setCriteria(criteria);
        template.setName("TestTemplate Name");
        template.setDescription("TestTemplate Description");
        template.setTemplateType(EMAIL_ACCOUNT_EXISTS);
        // These should be ignored
        template.setDeleted(true);
        
        ForDevelopersApi devsApi = developer.getClient(ForDevelopersApi.class);<commit_msg>This needs to be adjusted based on new exception being thrown.<commit_after>package org.sagebionetworks.bridge.sdk.integration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.sagebionetworks.bridge.rest.model.Role.DEVELOPER;
import static org.sagebionetworks.bridge.rest.model.TemplateType.EMAIL_ACCOUNT_EXISTS;

import com.google.common.collect.ImmutableMap;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.sagebionetworks.bridge.rest.api.ForAdminsApi;
import org.sagebionetworks.bridge.rest.api.ForDevelopersApi;
import org.sagebionetworks.bridge.rest.exceptions.EntityNotFoundException;
import org.sagebionetworks.bridge.rest.model.Criteria;
import org.sagebionetworks.bridge.rest.model.GuidVersionHolder;
import org.sagebionetworks.bridge.rest.model.Template;
import org.sagebionetworks.bridge.rest.model.TemplateList;
import org.sagebionetworks.bridge.user.TestUserHelper;
import org.sagebionetworks.bridge.user.TestUserHelper.TestUser;

public class TemplateTest {
    
    TestUser admin;
    TestUser developer;
    Template template;
    
    @Before
    public void before() throws Exception {
        admin = TestUserHelper.getSignedInAdmin();
        developer = TestUserHelper.createAndSignInUser(TemplateTest.class, true, DEVELOPER);
    }
    
    @After
    public void after() throws Exception {
        // in case of earlier test failure, clean up
        if (template != null && template.getGuid() != null) {
            ForAdminsApi adminsApi = admin.getClient(ForAdminsApi.class);
            try {
                adminsApi.deleteTemplate(template.getGuid(), true).execute();    
            } catch(EntityNotFoundException e) {
                // this is okay
            }
        }
        developer.signOutAndDeleteUser();
    }
    
    @Test
    public void crudTemplate() throws Exception {
        Criteria criteria = new Criteria();
        criteria.setMinAppVersions(ImmutableMap.of("Android", 10));
        criteria.setMaxAppVersions(ImmutableMap.of("Android", 100));
        
        // create template
        template = new Template();
        template.setCriteria(criteria);
        template.setName("TestTemplate Name");
        template.setDescription("TestTemplate Description");
        template.setTemplateType(EMAIL_ACCOUNT_EXISTS);
        // These should be ignored
        template.setDeleted(true);
        
        ForDevelopersApi devsApi = developer.getClient(ForDevelopersApi.class);
{'fraction_non_alphanumeric': 0.09453413732736822, 'fraction_numerical': 0.0019451468585878235, 'mean_word_length': 3.6324324324324326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6080741', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1483, 'n_words': 268}