Package org.internna.ossmoney.services.impl

Source Code of org.internna.ossmoney.services.impl.UserServiceTest

package org.internna.ossmoney.services.impl;

import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import org.internna.ossmoney.model.Payee;
import org.internna.ossmoney.model.Dashboard;
import org.internna.ossmoney.util.StringUtils;
import org.internna.ossmoney.util.SecurityUtils;
import org.internna.ossmoney.model.security.UserDetails;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.test.context.transaction.TransactionConfiguration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(defaultRollback = true)
@ContextConfiguration(locations = {"classpath:/META-INF/spring/applicationContext.xml", "classpath:/META-INF/spring/applicationContext-security.xml"})
public class UserServiceTest {

  @Autowired private UserService service;
  @Autowired private AuthenticationManager authenticationManager;

  @Test
  public void testCreateDashboard() {
    Dashboard dashboard = service.createDashBoDashboard();
    assertNotNull("Dashboard created", dashboard);
    assertNotNull("Dashboard persisted", dashboard.getId());
  }

  @Test
  public void testCreateUser() throws NoSuchAlgorithmException, UnsupportedEncodingException {
    Dashboard dashboard = service.createDashBoDashboard();
    UserDetails user = service.createUser("foobar", "baz", "Foo Bar", "foo@bar.es", dashboard);
    assertNotNull("User created", user);
    assertEquals("Password encoded", StringUtils.SHA1("finance", "baz"), user.getPassword());
    assertNotNull("Budget created", user.getBudget());
    SecurityUtils.authenticate(authenticationManager, "foobar", "baz");
    assertNotNull("Payee created", Payee.findByName(user.getName()));
    assertEquals("Twelve months", 12, user.getBudget().getBudgets().size());
  }

}
TOP

Related Classes of org.internna.ossmoney.services.impl.UserServiceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.