}
				}
				return false
			}).Should(Equal(true))

			By("Get a login user")
			uid, ut, err := util.UserLogin(app, "user123", "pass")
			user = common.User{ID: uid, Token: ut}
			Expect(err).To(Succeed())

			By("Add the logged-in user as owner of gateway")
			err = util.AddOwner(app, user.ID, user.Token, gwID, "password")
			Expect(err).To(Succeed())

			By("Onboard new end-node to cloud")
			enID, err = util.OnboardNode(app, user, gwID, newVid, "pass")
			Expect(err).To(Succeed())
			Expect(enID).ShouldNot(Equal(""))

			By("Notify gateway-agent with onboarding end-node completion")
			_, err = util.MapNode(tConfig.GatewayAddress, app, common.Node{ID: enID, VID: newVid}, t)
			Expect(err).To(Succeed())

			By("New end-node should be in the onboarded list")
			Eventually(func() bool {
				p, _, err := util.ListOnboardedNodes(tConfig.GatewayAddress, app, t)
				if err != nil {
					return false
				}
				for _, node := range p {
					vid, _ := dproxy.New(node).M("vendorThingID").String()
	var client1 mqtt.Client
	BeforeEach(func() {
		master = tConfig.Apps["master"]
		addr = tConfig.GatewayAddress
		en = tConfig.Apps["enApp1"]

		By("Prepare endnode app")
		uid, ut, err := util.UserLogin(en, "user123", "pass")
		eUser = common.User{ID: uid, Token: ut}
		Expect(err).To(Succeed())
		gwID, err := util.OnboardGatewayAnonymous(en, gwConfig.Gateway.VendorThingID, gwConfig.Gateway.ThingPassword)
		Expect(err).To(Succeed())
		Expect(util.AddOwner(en, eUser.ID, eUser.Token, gwID, gwConfig.Gateway.ThingPassword)).To(Succeed())
		eGwID = gwID
		enVid := fmt.Sprintf("vid-%d", time.Now().UnixNano()/int64(time.Millisecond))
		enID, err := util.OnboardNode(en, eUser, eGwID, enVid, "pass")
		Expect(err).To(Succeed())
		Expect(enID).NotTo(Equal(""))
		eEnID = enID
		eEnVID = enVid

		By("Prepare gateway app")
		uid, ut, err = util.UserLogin(master, "user123", "pass")
		mUser = common.User{ID: uid, Token: ut}
		Expect(err).To(Succeed())
		gwID, err = util.OnboardGatewayAnonymous(master, gwConfig.Gateway.VendorThingID, gwConfig.Gateway.ThingPassword)
		Expect(err).To(Succeed())
		Expect(util.AddOwner(master, mUser.ID, mUser.Token, gwID, gwConfig.Gateway.ThingPassword)).To(Succeed())
		mGwID = gwID
		enVid = fmt.Sprintf("vid-%d", time.Now().UnixNano()/int64(time.Millisecond))
		enID, err = util.OnboardNode(master, mUser, mGwID, enVid, "pass")