broker               brokerapi.ServiceBroker
		binder               *fakes.FakeBindingInfoBuilder
	)

	BeforeEach(func() {
		config = &rabbitbroker.Config{}
		client = new(fakes.FakeAPIClient)
		client.PutUserReturns(&http.Response{StatusCode: http.StatusNoContent}, nil)
		client.UpdatePermissionsInReturns(&http.Response{StatusCode: http.StatusNoContent}, nil)
		credentialsGenerator = new(fakes.FakeCredentialsGenerator)
		binder = new(fakes.FakeBindingInfoBuilder)
		broker = rabbitbroker.New(config, client, credentialsGenerator, lagertest.NewTestLogger("test"), binder)
	})

	It("uses generated user credentials", func() {
		credentialsGenerator.GenerateReturns(rabbitbroker.Credentials{Username: "******", Password: "******"})
		_, err := broker.Bind("my-instance", "my-binding", brokerapi.BindDetails{})
		Expect(err).NotTo(HaveOccurred())

		Expect(client.PutUserCallCount()).To(Equal(1))
		username, userInfo := client.PutUserArgsForCall(0)
		Expect(username).To(Equal("bob"))
		Expect(userInfo.Name).To(Equal("bob"))
		Expect(userInfo.Password).To(Equal("sekrit"))
	})

	It("constructs a binding using the Binder", func() {
		credentialsGenerator.GenerateReturns(rabbitbroker.Credentials{Username: "******", Password: "******"})
		config.Rabbitmq = rabbitbroker.RabbitmqConfig{ManagementDomain: "some-domain"}
		expectedConfig := rabbitbroker.RabbitmqConfig{
			ManagementDomain: "some-domain",
		broker = rabbitbroker.New(config, client, credentialsGenerator, logger, nil)
	})

	Context("Provision", func() {

		BeforeEach(func() {
			client.GetVhostReturns(nil, fmt.Errorf("vhost does not exist"))
			client.PutVhostReturns(&http.Response{StatusCode: http.StatusNoContent}, nil)
			client.DeleteVhostReturns(&http.Response{StatusCode: http.StatusNoContent}, nil)
			client.UpdatePermissionsInReturns(&http.Response{StatusCode: http.StatusNoContent}, nil)
			client.PutPolicyReturns(&http.Response{StatusCode: http.StatusNoContent}, nil)
			client.PutUserReturns(&http.Response{StatusCode: http.StatusNoContent}, nil)
			client.GetUserReturns(nil, fmt.Errorf(rabbitbroker.NotFoundIdentifier))

			credentialsGenerator.GenerateReturns(rabbitbroker.Credentials{
				Username: "******",
				Password: "******",
			})
		})

		It("returns no error", func() {
			_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
			Expect(err).NotTo(HaveOccurred())
		})

		It("logs a message stating that it is provisioning", func() {
			_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
			Expect(err).NotTo(HaveOccurred())
			Expect(logger.LogMessages()).To(ContainElement(ContainSubstring("Asked to provision a service: my-service-id")))
		})

		It("returns a dashboard url", func() {